
All code for unit tests is now under the `PhpSpreadsheet\Tests` namespace which is autoloaded via composer mechanism. So there is no need for `require()` anymore. Also, tests were moved in `tests/` folder and phpunit should be executed from the project root folder. This is to conform to the de facto standard, notably in use in phpunit itself.
88 lines
2.6 KiB
PHP
88 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace PhpSpreadsheet\Tests\Worksheet;
|
|
|
|
use PHPExcel\Worksheet\ColumnIterator;
|
|
|
|
class ColumnIteratorTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public $mockWorksheet;
|
|
public $mockColumn;
|
|
|
|
public function setUp()
|
|
{
|
|
$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 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 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 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 ColumnIterator($this->mockWorksheet, 'B', 'D');
|
|
$iterator->seek('A');
|
|
}
|
|
|
|
/**
|
|
* @expectedException \PHPExcel\Exception
|
|
*/
|
|
public function testPrevOutOfRange()
|
|
{
|
|
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
|
|
$iterator->prev();
|
|
}
|
|
}
|