Implement a ColumnIterator, refactoring of RowIterator

Currently this disables the setIterateOnlyExistingCells option

TODO Re-Implement setIterateOnlyExistingCells logic with the new structure
TODO Rationalise and abstract common methods in the iterator classes
This commit is contained in:
MarkBaker 2015-04-26 13:00:58 +01:00
parent f96d9cedba
commit ceddc13f82
13 changed files with 922 additions and 6 deletions

View File

@ -2568,6 +2568,18 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
return new PHPExcel_Worksheet_RowIterator($this, $startRow, $endRow);
}
/**
* Get column iterator
*
* @param string $startColumn The column address at which to start iterating
* @param string $endColumn The column address at which to stop iterating
*
* @return PHPExcel_Worksheet_ColumnIterator
*/
public function getColumnIterator($startColumn = 'A', $endColumn = null) {
return new PHPExcel_Worksheet_ColumnIterator($this, $startColumn, $endColumn);
}
/**
* Run PHPExcel garabage collector.
*

View File

@ -22,7 +22,7 @@
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
* @version 1.8.0, 2014-03-02
*/

View File

@ -0,0 +1,90 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Worksheet_Column
*
* Represents a column in PHPExcel_Worksheet, used by PHPExcel_Worksheet_ColumnIterator
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Worksheet_Column
{
/**
* PHPExcel_Worksheet
*
* @var PHPExcel_Worksheet
*/
private $_parent;
/**
* Column index
*
* @var string
*/
private $_columnIndex;
/**
* Create a new column
*
* @param PHPExcel_Worksheet $parent
* @param string $columnIndex
*/
public function __construct(PHPExcel_Worksheet $parent = null, $columnIndex = 'A') {
// Set parent and column index
$this->_parent = $parent;
$this->_columnIndex = $columnIndex;
}
/**
* Destructor
*/
public function __destruct() {
unset($this->_parent);
}
/**
* Get column index
*
* @return int
*/
public function getColumnIndex() {
return $this->_columnIndex;
}
/**
* Get cell iterator
*
* @return PHPExcel_Worksheet_CellIterator
*/
public function getCellIterator() {
return new PHPExcel_Worksheet_ColumnCellIterator($this->_parent, $this->_columnIndex);
}
}

View File

@ -0,0 +1,215 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Worksheet_ColumnCellIterator
*
* Used to iterate columns in a PHPExcel_Worksheet
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Worksheet_ColumnCellIterator implements Iterator
{
/**
* PHPExcel_Worksheet to iterate
*
* @var PHPExcel_Worksheet
*/
private $_subject;
/**
* Column index
*
* @var string
*/
private $_columnIndex;
/**
* Current iterator position
*
* @var int
*/
private $_position = 1;
/**
* Start position
*
* @var int
*/
private $_startRow = 1;
/**
* End position
*
* @var int
*/
private $_endRow = 1;
/**
* Loop only existing cells
*
* @var boolean
*/
private $_onlyExistingCells = true;
/**
* Create a new row iterator
*
* @param PHPExcel_Worksheet $subject The worksheet to iterate over
* @param string $columnIndex The column that we want to iterate
* @param integer $startRow The row number at which to start iterating
* @param integer $endRow Optionally, the row number at which to stop iterating
*/
public function __construct(PHPExcel_Worksheet $subject = null, $columnIndex, $startRow = 1, $endRow = null) {
// Set subject
$this->_subject = $subject;
$this->_columnIndex = PHPExcel_Cell::columnIndexFromString($columnIndex) - 1;
$this->resetEnd($endRow);
$this->resetStart($startRow);
}
/**
* Destructor
*/
public function __destruct() {
unset($this->_subject);
}
/**
* (Re)Set the start row and the current row pointer
*
* @param integer $startRow The row number at which to start iterating
* @return PHPExcel_Worksheet_RowIterator
*/
public function resetStart($startRow = 1) {
$this->_startRow = $startRow;
$this->seek($startRow);
return $this;
}
/**
* (Re)Set the end row
*
* @param integer $endRow The row number at which to stop iterating
* @return PHPExcel_Worksheet_RowIterator
*/
public function resetEnd($endRow = null) {
$this->_endRow = ($endRow) ? $endRow : $this->_subject->getHighestRow();
return $this;
}
/**
* Set the row pointer to the selected row
*
* @param integer $row The row number to set the current pointer at
* @return PHPExcel_Worksheet_RowIterator
* @throws PHPExcel_Exception
*/
public function seek($row = 1) {
if (($row < $this->_startRow) || ($row > $this->_endRow)) {
throw new PHPExcel_Exception("Row $row is out of range ({$this->_startRow} - {$this->_endRow})");
}
$this->_position = $row;
return $this;
}
/**
* Rewind the iterator to the starting row
*/
public function rewind() {
$this->_position = $this->_startRow;
}
/**
* Return the current row in this worksheet
*
* @return PHPExcel_Worksheet_Row
*/
public function current() {
return $this->_subject->getCellByColumnAndRow($this->_columnIndex, $this->_position);
}
/**
* Return the current iterator key
*
* @return int
*/
public function key() {
return $this->_position;
}
/**
* Set the iterator to its next value
*/
public function next() {
++$this->_position;
}
/**
* Set the iterator to its previous value
*/
public function prev() {
if ($this->_position <= $this->_startRow) {
throw new PHPExcel_Exception("Row is already at the beginning of range ({$this->_startRow} - {$this->_endRow})");
}
--$this->_position;
}
/**
* Indicate if more rows exist in the worksheet range of rows that we're iterating
*
* @return boolean
*/
public function valid() {
return $this->_position <= $this->_endRow;
}
/**
* Get loop only existing cells
*
* @return boolean
*/
public function getIterateOnlyExistingCells() {
return $this->_onlyExistingCells;
}
/**
* Set the iterator to loop only existing cells
*
* @param boolean $value
*/
public function setIterateOnlyExistingCells($value = true) {
$this->_onlyExistingCells = $value;
}
}

View File

@ -0,0 +1,192 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Worksheet_ColumnIterator
*
* Used to iterate columns in a PHPExcel_Worksheet
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Worksheet_ColumnIterator implements Iterator
{
/**
* PHPExcel_Worksheet to iterate
*
* @var PHPExcel_Worksheet
*/
private $_subject;
/**
* Current iterator position
*
* @var int
*/
private $_position = 0;
/**
* Start position
*
* @var int
*/
private $_startColumn = 0;
/**
* End position
*
* @var int
*/
private $_endColumn = 0;
/**
* Create a new column iterator
*
* @param PHPExcel_Worksheet $subject The worksheet to iterate over
* @param string $startColumn The column address at which to start iterating
* @param string $endColumn Optionally, the column address at which to stop iterating
*/
public function __construct(PHPExcel_Worksheet $subject = null, $startColumn = 'A', $endColumn = null) {
// Set subject
$this->_subject = $subject;
$this->resetEnd($endColumn);
$this->resetStart($startColumn);
}
/**
* Destructor
*/
public function __destruct() {
unset($this->_subject);
}
/**
* (Re)Set the start column and the current column pointer
*
* @param integer $startColumn The column address at which to start iterating
* @return PHPExcel_Worksheet_ColumnIterator
*/
public function resetStart($startColumn = 'A') {
$startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1;
$this->_startColumn = $startColumnIndex;
$this->seek($startColumn);
return $this;
}
/**
* (Re)Set the end column
*
* @param string $endColumn The column address at which to stop iterating
* @return PHPExcel_Worksheet_ColumnIterator
*/
public function resetEnd($endColumn = null) {
$endColumn = ($endColumn) ? $endColumn : $this->_subject->getHighestColumn();
$this->_endColumn = PHPExcel_Cell::columnIndexFromString($endColumn) - 1;
return $this;
}
/**
* Set the column pointer to the selected column
*
* @param string $column The column address to set the current pointer at
* @return PHPExcel_Worksheet_ColumnIterator
* @throws PHPExcel_Exception
*/
public function seek($column = 'A') {
$column = PHPExcel_Cell::columnIndexFromString($column) - 1;
if (($column < $this->_startColumn) || ($column > $this->_endColumn)) {
throw new PHPExcel_Exception("Column $column is out of range ({$this->_startColumn} - {$this->_endColumn})");
}
$this->_position = $column;
return $this;
}
/**
* Rewind the iterator to the starting column
*/
public function rewind() {
$this->_position = $this->_startColumn;
}
/**
* Return the current column in this worksheet
*
* @return PHPExcel_Worksheet_Column
*/
public function current() {
return new PHPExcel_Worksheet_Column($this->_subject, PHPExcel_Cell::stringFromColumnIndex($this->_position));
}
/**
* Return the current iterator key
*
* @return string
*/
public function key() {
return PHPExcel_Cell::stringFromColumnIndex($this->_position);
}
/**
* Set the iterator to its next value
*/
public function next() {
++$this->_position;
}
/**
* Set the iterator to its previous value
*
* @throws PHPExcel_Exception
*/
public function prev() {
if ($this->_position <= $this->_startColumn) {
throw new PHPExcel_Exception(
"Column is already at the beginning of range (" .
PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . " - " .
PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . ")"
);
}
--$this->_position;
}
/**
* Indicate if more columns exist in the worksheet range of columns that we're iterating
*
* @return boolean
*/
public function valid() {
return $this->_position <= $this->_endColumn;
}
}

View File

@ -85,6 +85,6 @@ class PHPExcel_Worksheet_Row
* @return PHPExcel_Worksheet_CellIterator
*/
public function getCellIterator() {
return new PHPExcel_Worksheet_CellIterator($this->_parent, $this->_rowIndex);
return new PHPExcel_Worksheet_RowCellIterator($this->_parent, $this->_rowIndex);
}
}

View File

@ -0,0 +1,224 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2014 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Worksheet_RowCellIterator
*
* Used to iterate columns in a PHPExcel_Worksheet
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Worksheet_RowCellIterator implements Iterator
{
/**
* PHPExcel_Worksheet to iterate in
*
* @var PHPExcel_Worksheet
*/
private $_subject;
/**
* Row index
*
* @var int
*/
private $_rowIndex;
/**
* Current iterator position
*
* @var int
*/
private $_position = 0;
/**
* Start position
*
* @var int
*/
private $_startColumn = 0;
/**
* End position
*
* @var int
*/
private $_endColumn = 0;
/**
* Loop only existing cells
*
* @var boolean
*/
private $_onlyExistingCells = true;
/**
* Create a new column iterator
*
* @param PHPExcel_Worksheet $subject The worksheet to iterate over
* @param integer $rowIndex The row that we want to iterate
* @param string $startColumn The column address at which to start iterating
* @param string $endColumn Optionally, the column address at which to stop iterating
*/
public function __construct(PHPExcel_Worksheet $subject = null, $rowIndex = 1, $startColumn = 'A', $endColumn = null) {
// Set subject and row index
$this->_subject = $subject;
$this->_rowIndex = $rowIndex;
$this->resetEnd($endColumn);
$this->resetStart($startColumn);
}
/**
* Destructor
*/
public function __destruct() {
unset($this->_subject);
}
/**
* (Re)Set the start column and the current column pointer
*
* @param integer $startColumn The column address at which to start iterating
* @return PHPExcel_Worksheet_RowCellIterator
*/
public function resetStart($startColumn = 'A') {
$startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1;
$this->_startColumn = $startColumnIndex;
$this->seek($startColumn);
return $this;
}
/**
* (Re)Set the end column
*
* @param string $endColumn The column address at which to stop iterating
* @return PHPExcel_Worksheet_RowCellIterator
*/
public function resetEnd($endColumn = null) {
$endColumn = ($endColumn) ? $endColumn : $this->_subject->getHighestColumn();
$this->_endColumn = PHPExcel_Cell::columnIndexFromString($endColumn) - 1;
return $this;
}
/**
* Set the column pointer to the selected column
*
* @param string $column The column address to set the current pointer at
* @return PHPExcel_Worksheet_RowCellIterator
* @throws PHPExcel_Exception
*/
public function seek($column = 'A') {
$column = PHPExcel_Cell::columnIndexFromString($column) - 1;
if (($column < $this->_startColumn) || ($column > $this->_endColumn)) {
throw new PHPExcel_Exception("Column $column is out of range ({$this->_startColumn} - {$this->_endColumn})");
}
$this->_position = $column;
return $this;
}
/**
* Rewind the iterator to the starting column
*/
public function rewind() {
$this->_position = $this->_startColumn;
}
/**
* Return the current cell in this worksheet row
*
* @return PHPExcel_Cell
*/
public function current() {
return $this->_subject->getCellByColumnAndRow($this->_position, $this->_rowIndex);
}
/**
* Return the current iterator key
*
* @return string
*/
public function key() {
return PHPExcel_Cell::stringFromColumnIndex($this->_position);
}
/**
* Set the iterator to its next value
*/
public function next() {
++$this->_position;
}
/**
* Set the iterator to its previous value
*
* @throws PHPExcel_Exception
*/
public function prev() {
if ($this->_position <= $this->_startColumn) {
throw new PHPExcel_Exception(
"Column is already at the beginning of range (" .
PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . " - " .
PHPExcel_Cell::stringFromColumnIndex($this->_endColumn) . ")"
);
}
--$this->_position;
}
/**
* Indicate if more columns exist in the worksheet range of columns that we're iterating
*
* @return boolean
*/
public function valid() {
return $this->_position <= $this->_endColumn;
}
/**
* Get loop only existing cells
*
* @return boolean
*/
public function getIterateOnlyExistingCells() {
return $this->_onlyExistingCells;
}
/**
* Set the iterator to loop only existing cells
*
* @param boolean $value
*/
public function setIterateOnlyExistingCells($value = true) {
$this->_onlyExistingCells = $value;
}
}

View File

@ -92,6 +92,7 @@ class PHPExcel_Worksheet_RowIterator implements Iterator
* (Re)Set the start row and the current row pointer
*
* @param integer $startRow The row number at which to start iterating
* @return PHPExcel_Worksheet_RowIterator
*/
public function resetStart($startRow = 1) {
$this->_startRow = $startRow;
@ -104,6 +105,7 @@ class PHPExcel_Worksheet_RowIterator implements Iterator
* (Re)Set the end row
*
* @param integer $endRow The row number at which to stop iterating
* @return PHPExcel_Worksheet_RowIterator
*/
public function resetEnd($endRow = null) {
$this->_endRow = ($endRow) ? $endRow : $this->_subject->getHighestRow();
@ -115,13 +117,16 @@ class PHPExcel_Worksheet_RowIterator implements Iterator
* Set the row pointer to the selected row
*
* @param integer $row The row number to set the current pointer at
* @return PHPExcel_Worksheet_RowIterator
* @throws PHPExcel_Exception
*/
public function seek($row = 1) {
if (($row < $this->_startRow) || ($row > $this->_endRow)) {
throw new PHPExcel_Exception("Row $row is out of range ({$this->_startRow} - {$this->_endRow})");
}
$this->_position = $row;
return $this;
}
/**

View File

@ -0,0 +1,89 @@
<?php
class ColumnIteratorTest extends PHPUnit_Framework_TestCase
{
public $mockWorksheet;
public $mockColumn;
public function setUp()
{
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
$this->mockColumn = $this->getMockBuilder('PHPExcel_Worksheet_Column')
->disableOriginalConstructor()
->getMock();
$this->mockWorksheet = $this->getMockBuilder('PHPExcel_Worksheet')
->disableOriginalConstructor()
->getMock();
$this->mockWorksheet->expects($this->any())
->method('getHighestColumn')
->will($this->returnValue('E'));
$this->mockWorksheet->expects($this->any())
->method('current')
->will($this->returnValue($this->mockColumn));
}
public function testIteratorFullRange()
{
$iterator = new PHPExcel_Worksheet_ColumnIterator($this->mockWorksheet);
$columnIndexResult = 'A';
$this->assertEquals($columnIndexResult, $iterator->key());
foreach($iterator as $key => $column) {
$this->assertEquals($columnIndexResult++, $key);
$this->assertInstanceOf('PHPExcel_Worksheet_Column', $column);
}
}
public function testIteratorStartEndRange()
{
$iterator = new PHPExcel_Worksheet_ColumnIterator($this->mockWorksheet, 'B', 'D');
$columnIndexResult = 'B';
$this->assertEquals($columnIndexResult, $iterator->key());
foreach($iterator as $key => $column) {
$this->assertEquals($columnIndexResult++, $key);
$this->assertInstanceOf('PHPExcel_Worksheet_Column', $column);
}
}
public function testIteratorSeekAndPrev()
{
$ranges = range('A','E');
$iterator = new PHPExcel_Worksheet_ColumnIterator($this->mockWorksheet, 'B', 'D');
$columnIndexResult = 'D';
$iterator->seek('D');
$this->assertEquals($columnIndexResult, $iterator->key());
for($i = 1; $i < array_search($columnIndexResult, $ranges); $i++) {
$iterator->prev();
$expectedResult = $ranges[array_search($columnIndexResult, $ranges) - $i];
$this->assertEquals($expectedResult, $iterator->key());
}
}
/**
* @expectedException PHPExcel_Exception
*/
public function testSeekOutOfRange()
{
$iterator = new PHPExcel_Worksheet_ColumnIterator($this->mockWorksheet, 'B', 'D');
$iterator->seek(1);
}
/**
* @expectedException PHPExcel_Exception
*/
public function testPrevOutOfRange()
{
$iterator = new PHPExcel_Worksheet_ColumnIterator($this->mockWorksheet, 'B', 'D');
$iterator->prev();
}
}

View File

@ -55,12 +55,12 @@ class RowIteratorTest extends PHPUnit_Framework_TestCase
public function testIteratorSeekAndPrev()
{
$iterator = new PHPExcel_Worksheet_RowIterator($this->mockWorksheet);
$iterator = new PHPExcel_Worksheet_RowIterator($this->mockWorksheet, 2, 4);
$columnIndexResult = 4;
$iterator->seek(4);
$this->assertEquals($columnIndexResult, $iterator->key(), 2, 4);
$this->assertEquals($columnIndexResult, $iterator->key());
for($i = 1; $i < $columnIndexResult; $i++) {
for($i = 1; $i < $columnIndexResult-1; $i++) {
$iterator->prev();
$this->assertEquals($columnIndexResult - $i, $iterator->key());
}

View File

@ -0,0 +1,43 @@
<?php
class ColumnTest extends PHPUnit_Framework_TestCase
{
public $mockWorksheet;
public $mockColumn;
public function setUp()
{
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
$this->mockWorksheet = $this->getMockBuilder('PHPExcel_Worksheet')
->disableOriginalConstructor()
->getMock();
}
public function testInstantiateColumnDefault()
{
$column = new PHPExcel_Worksheet_Column($this->mockWorksheet);
$this->assertInstanceOf('PHPExcel_Worksheet_Column', $column);
$columnIndex = $column->getColumnIndex();
$this->assertEquals('A', $columnIndex);
}
public function testInstantiateColumnSpecified()
{
$column = new PHPExcel_Worksheet_Column($this->mockWorksheet, 'E');
$this->assertInstanceOf('PHPExcel_Worksheet_Column', $column);
$columnIndex = $column->getColumnIndex();
$this->assertEquals('E', $columnIndex);
}
public function testGetCellIterator()
{
$column = new PHPExcel_Worksheet_Column($this->mockWorksheet);
$cellIterator = $column->getCellIterator();
$this->assertInstanceOf('PHPExcel_Worksheet_CellIterator', $cellIterator);
}
}

View File

@ -0,0 +1,43 @@
<?php
class WorksheetRowTest extends PHPUnit_Framework_TestCase
{
public $mockWorksheet;
public $mockRow;
public function setUp()
{
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
$this->mockWorksheet = $this->getMockBuilder('PHPExcel_Worksheet')
->disableOriginalConstructor()
->getMock();
}
public function testInstantiateRowDefault()
{
$row = new PHPExcel_Worksheet_Row($this->mockWorksheet);
$this->assertInstanceOf('PHPExcel_Worksheet_Row', $row);
$rowIndex = $row->getRowIndex();
$this->assertEquals(1, $rowIndex);
}
public function testInstantiateRowSpecified()
{
$row = new PHPExcel_Worksheet_Row($this->mockWorksheet, 5);
$this->assertInstanceOf('PHPExcel_Worksheet_Row', $row);
$rowIndex = $row->getRowIndex();
$this->assertEquals(5, $rowIndex);
}
public function testGetCellIterator()
{
$row = new PHPExcel_Worksheet_Row($this->mockWorksheet);
$cellIterator = $row->getCellIterator();
$this->assertInstanceOf('PHPExcel_Worksheet_CellIterator', $cellIterator);
}
}

View File

@ -13,6 +13,9 @@
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
<php>
<ini name="memory_limit" value="2048M"/>
</php>
<testsuite name="PHPExcel Unit Test Suite">
<directory suffix="Test.php">./Classes</directory>
</testsuite>