PhpSpreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php

90 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
2016-03-22 14:35:50 +00:00
use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator;
use PHPUnit_Framework_TestCase;
class RowCellIteratorTest extends PHPUnit_Framework_TestCase
{
public $mockWorksheet;
public $mockRowCell;
2015-05-17 13:00:02 +00:00
public function setUp()
{
$this->mockCell = $this->getMockBuilder(Cell::class)
->disableOriginalConstructor()
->getMock();
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
->disableOriginalConstructor()
->getMock();
$this->mockWorksheet->expects($this->any())
->method('getHighestColumn')
->will($this->returnValue('E'));
$this->mockWorksheet->expects($this->any())
->method('getCellByColumnAndRow')
->will($this->returnValue($this->mockCell));
}
2015-05-17 13:00:02 +00:00
public function testIteratorFullRange()
{
$iterator = new RowCellIterator($this->mockWorksheet);
$RowCellIndexResult = 'A';
self::assertEquals($RowCellIndexResult, $iterator->key());
2015-05-17 13:00:02 +00:00
foreach ($iterator as $key => $RowCell) {
self::assertEquals($RowCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $RowCell);
}
2015-05-17 13:00:02 +00:00
}
2015-05-17 13:00:02 +00:00
public function testIteratorStartEndRange()
{
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$RowCellIndexResult = 'B';
self::assertEquals($RowCellIndexResult, $iterator->key());
2015-05-17 13:00:02 +00:00
foreach ($iterator as $key => $RowCell) {
self::assertEquals($RowCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $RowCell);
}
2015-05-17 13:00:02 +00:00
}
2015-05-17 13:00:02 +00:00
public function testIteratorSeekAndPrev()
{
2015-05-17 17:26:34 +00:00
$ranges = range('A', 'E');
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$RowCellIndexResult = 'D';
$iterator->seek('D');
self::assertEquals($RowCellIndexResult, $iterator->key());
for ($i = 1; $i < array_search($RowCellIndexResult, $ranges); ++$i) {
$iterator->prev();
$expectedResult = $ranges[array_search($RowCellIndexResult, $ranges) - $i];
self::assertEquals($expectedResult, $iterator->key());
}
2015-05-17 13:00:02 +00:00
}
/**
* @expectedException \PhpOffice\PhpSpreadsheet\Exception
*/
public function testSeekOutOfRange()
{
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$iterator->seek(1);
}
/**
* @expectedException \PhpOffice\PhpSpreadsheet\Exception
*/
public function testPrevOutOfRange()
{
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$iterator->prev();
}
}