spout/tests/Spout/Reader/XLSX/Manager/RowManagerTest.php
2017-11-18 20:53:22 +01:00

91 lines
2.3 KiB
PHP

<?php
namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
/**
* Class SharedStringsManagerTest
*/
class RowManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestFillMissingIndexesWithEmptyCells()
{
$cell1 = new Cell(1);
$cell3 = new Cell(3);
return [
[[], []],
[[1 => $cell1, 3 => $cell3], [new Cell(''), $cell1, new Cell(''), $cell3]],
];
}
/**
* @dataProvider dataProviderForTestFillMissingIndexesWithEmptyCells
*
* @param Cell[]|null $rowCells
* @param Cell[] $expectedFilledCells
*/
public function testFillMissingIndexesWithEmptyCells($rowCells, $expectedFilledCells)
{
$rowManager = $this->createRowManager();
$rowToFill = new Row([]);
foreach ($rowCells as $cellIndex => $cell) {
$rowToFill->setCellAtIndex($cell, $cellIndex);
}
$filledRow = $rowManager->fillMissingIndexesWithEmptyCells($rowToFill);
$this->assertEquals($expectedFilledCells, $filledRow->getCells());
}
/**
* @return array
*/
public function dataProviderForTestIsEmptyRow()
{
return [
// cells, expected isEmpty
[[], true],
[[new Cell('')], true],
[[new Cell(''), new Cell('')], true],
[[new Cell(''), new Cell(''), new Cell('Okay')], false],
];
}
/**
* @dataProvider dataProviderForTestIsEmptyRow
*
* @param array $cells
* @param bool $expectedIsEmpty
* @return void
*/
public function testIsEmptyRow(array $cells, $expectedIsEmpty)
{
$rowManager = $this->createRowManager();
$row = new Row($cells);
$this->assertEquals($expectedIsEmpty, $rowManager->isEmpty($row));
}
/**
* @return RowManager
*/
private function createRowManager()
{
$entityFactory = new InternalEntityFactory(
$this->createMock(ManagerFactory::class),
$this->createMock(HelperFactory::class)
);
return new RowManager($entityFactory);
}
}