various improvements

This commit is contained in:
Adrien Loison committed 2017-11-19 02:41:07 +01:00
1 parent 102e17159c
commit 4d1d1c1e87
19 files changed
+90 -112

No files matched your search

+7 -7
View File
@@ -28,7 +28,7 @@ class RowTest extends \PHPUnit\Framework\TestCase
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
$this->assertEquals(2, $row->getNumCells());
}
/**
@@ -39,11 +39,11 @@ class RowTest extends \PHPUnit\Framework\TestCase
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
$this->assertEquals(2, $row->getNumCells());
$row->setCells([$this->getCellMock()]);
$this->assertEquals(1, count($row->getCells()));
$this->assertEquals(1, $row->getNumCells());
}
/**
@@ -53,11 +53,11 @@ class RowTest extends \PHPUnit\Framework\TestCase
{
$row = new Row([], null);
$this->assertEquals(0, count($row->getCells()));
$this->assertEquals(0, $row->getNumCells());
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
$this->assertEquals(2, $row->getNumCells());
}
/**
@@ -68,11 +68,11 @@ class RowTest extends \PHPUnit\Framework\TestCase
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, count($row->getCells()));
$this->assertEquals(2, $row->getNumCells());
$row->addCell($this->getCellMock());
$this->assertEquals(3, count($row->getCells()));
$this->assertEquals(3, $row->getNumCells());
}
/**
@@ -0,0 +1,90 @@
<?php
namespace Box\Spout\Reader\Common\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 RowManagerTest
*/
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);
}
}