From 84083985dc3444f1d3e43883f973e7b966afb87c Mon Sep 17 00:00:00 2001 From: Adrien Loison Date: Sat, 21 Oct 2017 17:55:51 +0200 Subject: [PATCH] Various improvements --- src/Spout/Writer/Common/Entity/Cell.php | 28 ++--- src/Spout/Writer/Common/Entity/Row.php | 46 ++++--- .../Writer/Common/Manager/CellManager.php | 3 +- .../Writer/Common/Manager/RowManager.php | 13 +- .../Common/Manager/Style/StyleManager.php | 15 ++- .../Writer/ODS/Creator/ManagerFactory.php | 2 - src/Spout/Writer/WriterAbstract.php | 39 +----- src/Spout/Writer/WriterInterface.php | 8 -- .../Writer/XLSX/Manager/WorksheetManager.php | 3 - .../XLSX/Helper/CellValueFormatterTest.php | 13 +- tests/Spout/Writer/CSV/WriterTest.php | 22 ++-- tests/Spout/Writer/Common/Entity/CellTest.php | 37 ++++-- tests/Spout/Writer/Common/Entity/RowTest.php | 115 +++++++++++------- .../Writer/Common/Manager/CellManagerTest.php | 28 +++++ .../Writer/Common/Manager/RowManagerTest.php | 83 ++++++++++--- tests/Spout/Writer/ODS/SheetTest.php | 15 ++- tests/Spout/Writer/ODS/WriterTest.php | 39 +++--- .../Spout/Writer/ODS/WriterWithStyleTest.php | 40 +++--- tests/Spout/Writer/XLSX/SheetTest.php | 15 ++- tests/Spout/Writer/XLSX/WriterTest.php | 45 +++---- .../Spout/Writer/XLSX/WriterWithStyleTest.php | 40 +++--- 21 files changed, 349 insertions(+), 300 deletions(-) create mode 100644 tests/Spout/Writer/Common/Manager/CellManagerTest.php diff --git a/src/Spout/Writer/Common/Entity/Cell.php b/src/Spout/Writer/Common/Entity/Cell.php index 7a33421..9660b42 100644 --- a/src/Spout/Writer/Common/Entity/Cell.php +++ b/src/Spout/Writer/Common/Entity/Cell.php @@ -56,7 +56,7 @@ class Cell /** * The cell style - * @var Style|null + * @var Style */ protected $style; @@ -66,9 +66,8 @@ class Cell protected $styleMerger; /** - * Cell constructor. * @param $value mixed - * @param $style|null Style + * @param Style|null $style */ public function __construct($value, Style $style = null) { @@ -78,7 +77,7 @@ class Cell } /** - * @param $value mixed|null + * @param mixed|null $value */ public function setValue($value) { @@ -95,22 +94,18 @@ class Cell } /** - * @param Style $style|null + * @param Style|null $style */ - public function setStyle(Style $style = null) + public function setStyle($style) { - $this->style = $style; + $this->style = $style ?: new Style(); } /** - * @return Style|null + * @return Style */ public function getStyle() { - if (!isset($this->style)) { - $this->setStyle(new Style()); - } - return $this->style; } @@ -124,6 +119,7 @@ class Cell /** * Get the current value type + * * @param mixed|null $value * @return int */ @@ -163,6 +159,7 @@ class Cell /** * Not used at the moment + * * @return bool */ public function isFormula() @@ -203,15 +200,16 @@ class Cell } /** - * @param Style $style|null + * @param Style|null $style * @return Cell */ - public function applyStyle(Style $style = null) + public function applyStyle($style) { if ($style === null) { return $this; } - $mergedStyle = $this->styleMerger->merge($this->getStyle(), $style); + + $mergedStyle = $this->styleMerger->merge($this->style, $style); $this->setStyle($mergedStyle); return $this; diff --git a/src/Spout/Writer/Common/Entity/Row.php b/src/Spout/Writer/Common/Entity/Row.php index 45395ab..fae771f 100644 --- a/src/Spout/Writer/Common/Entity/Row.php +++ b/src/Spout/Writer/Common/Entity/Row.php @@ -9,13 +9,13 @@ class Row { /** * The cells in this row - * @var array + * @var Cell[] */ protected $cells = []; /** * The row style - * @var Style|null + * @var Style */ protected $style; @@ -31,7 +31,7 @@ class Row * @param Style|null $style * @param RowManager $rowManager */ - public function __construct(array $cells = [], Style $style = null, RowManager $rowManager) + public function __construct(array $cells, $style, RowManager $rowManager) { $this ->setCells($cells) @@ -49,7 +49,7 @@ class Row } /** - * @param array $cells + * @param Cell[] $cells * @return $this */ public function setCells(array $cells) @@ -67,29 +67,25 @@ class Row */ public function getStyle() { - if (!isset($this->style)) { - $this->setStyle(new Style()); - } - return $this->style; } + /** + * @param Style|null $style + * @return Row + */ + public function setStyle($style) + { + $this->style = $style ?: new Style(); + + return $this; + } + /** * @param Style $style * @return Row */ - public function setStyle($style) - { - $this->style = $style; - - return $this; - } - - /** - * @param Style $style|null - * @return Row - */ - public function applyStyle(Style $style = null) + public function applyStyle($style) { $this->rowManager->applyStyle($this, $style); @@ -107,6 +103,16 @@ class Row return $this; } + /** + * Returns whether a row has cells + * + * @return bool + */ + public function hasCells() + { + return $this->rowManager->hasCells($this); + } + /** * Detect whether this row is considered empty. * An empty row has either no cells at all - or only empty cells diff --git a/src/Spout/Writer/Common/Manager/CellManager.php b/src/Spout/Writer/Common/Manager/CellManager.php index 29bd081..d320802 100644 --- a/src/Spout/Writer/Common/Manager/CellManager.php +++ b/src/Spout/Writer/Common/Manager/CellManager.php @@ -14,7 +14,6 @@ class CellManager protected $styleMerger; /** - * CellManager constructor. * @param StyleMerger $styleMerger */ public function __construct(StyleMerger $styleMerger) @@ -23,7 +22,7 @@ class CellManager } /** - * Merges a Style into a cells Style. + * Merges a Style into a cell's Style. * * @param Cell $cell * @param Style $style diff --git a/src/Spout/Writer/Common/Manager/RowManager.php b/src/Spout/Writer/Common/Manager/RowManager.php index f5d27ca..109fa06 100644 --- a/src/Spout/Writer/Common/Manager/RowManager.php +++ b/src/Spout/Writer/Common/Manager/RowManager.php @@ -14,7 +14,6 @@ class RowManager protected $styleMerger; /** - * RowManager constructor. * @param StyleMerger $styleMerger */ public function __construct(StyleMerger $styleMerger) @@ -23,6 +22,7 @@ class RowManager } /** + * @param Row $row * @param Style $style * @return $this */ @@ -32,6 +32,17 @@ class RowManager $row->setStyle($mergedStyle); } + /** + * Returns whether a row has cells + * + * @param Row $row + * @return bool + */ + public function hasCells(Row $row) + { + return count($row->getCells()) !== 0; + } + /** * Detect whether a row is considered empty. * An empty row has either no cells at all - or only one empty cell diff --git a/src/Spout/Writer/Common/Manager/Style/StyleManager.php b/src/Spout/Writer/Common/Manager/Style/StyleManager.php index 1835c24..9006d02 100644 --- a/src/Spout/Writer/Common/Manager/Style/StyleManager.php +++ b/src/Spout/Writer/Common/Manager/Style/StyleManager.php @@ -73,14 +73,17 @@ class StyleManager implements StyleManagerInterface */ protected function applyWrapTextIfCellContainsNewLine(Cell $cell) { + $cellStyle = $cell->getStyle(); + // if the "wrap text" option is already set, no-op - if ($cell->getStyle()->hasSetWrapText()) { - return $cell->getStyle(); - } - if ($cell->isString() && strpos($cell->getValue(), "\n") !== false) { - $cell->getStyle()->setShouldWrapText(); + if ($cellStyle->hasSetWrapText()) { + return $cellStyle; } - return $cell->getStyle(); + if ($cell->isString() && strpos($cell->getValue(), "\n") !== false) { + $cellStyle->setShouldWrapText(); + } + + return $cellStyle; } } diff --git a/src/Spout/Writer/ODS/Creator/ManagerFactory.php b/src/Spout/Writer/ODS/Creator/ManagerFactory.php index 3721b8e..7624c4c 100644 --- a/src/Spout/Writer/ODS/Creator/ManagerFactory.php +++ b/src/Spout/Writer/ODS/Creator/ManagerFactory.php @@ -69,8 +69,6 @@ class ManagerFactory implements ManagerFactoryInterface $stringsHelper = $this->helperFactory->createStringHelper(); return new WorksheetManager($styleManager, $stringsEscaper, $stringsHelper); - - return new WorksheetManager($stringsEscaper, $stringsHelper, $this->entityFactory); } /** diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index 6b1caf3..ad9c301 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -8,8 +8,6 @@ use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Exception\SpoutException; use Box\Spout\Common\Helper\GlobalFunctionsHelper; use Box\Spout\Common\Manager\OptionsManagerInterface; -use Box\Spout\Writer\Common\Creator\EntityFactory; -use Box\Spout\Writer\Common\Entity\Cell; use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Entity\Row; use Box\Spout\Writer\Common\Entity\Style\Style; @@ -119,6 +117,8 @@ abstract class WriterAbstract implements WriterInterface } /** + * @codeCoverageIgnore + * * {@inheritdoc} */ public function openToBrowser($outputFileName) @@ -187,7 +187,7 @@ abstract class WriterAbstract implements WriterInterface public function addRow(Row $row) { if ($this->isWriterOpened) { - if (!$row->isEmpty()) { + if ($row->hasCells()) { try { $this->applyDefaultRowStyle($row); $this->addRowToWriter($row); @@ -195,6 +195,7 @@ abstract class WriterAbstract implements WriterInterface // if an exception occurs while writing data, // close the writer and remove all files created so far. $this->closeAndAttemptToCleanupAllFiles(); + // re-throw the exception to alert developers of the error throw $e; } @@ -206,14 +207,6 @@ abstract class WriterAbstract implements WriterInterface return $this; } - /** - * {@inheritdoc} - */ - public function withRow(\Closure $callback) - { - return $this->addRow($callback(EntityFactory::createRow([]))); - } - /** * {@inheritdoc} */ @@ -231,28 +224,6 @@ abstract class WriterAbstract implements WriterInterface return $this; } - /** - * @param array $dataRow - * @param Style|null $style - * @return Row - */ - protected function createRowFromArray(array $dataRow, Style $style = null) - { - $row = EntityFactory::createRow(array_map(function ($value) { - if ($value instanceof Cell) { - return $value; - } - - return new Cell($value); - }, $dataRow)); - - if ($style !== null) { - $row->setStyle($style); - } - - return $row; - } - /** * @TODO: Move this into styleMerger * @@ -265,6 +236,7 @@ abstract class WriterAbstract implements WriterInterface if ($defaultRowStyle === null) { return $this; } + $mergedStyle = $this->styleMerger->merge($row->getStyle(), $defaultRowStyle); $row->setStyle($mergedStyle); } @@ -273,7 +245,6 @@ abstract class WriterAbstract implements WriterInterface * Closes the writer. This will close the streamer as well, preventing new data * to be written to the file. * - * @api * @return void */ public function close() diff --git a/src/Spout/Writer/WriterInterface.php b/src/Spout/Writer/WriterInterface.php index 0547f08..fd8d145 100644 --- a/src/Spout/Writer/WriterInterface.php +++ b/src/Spout/Writer/WriterInterface.php @@ -37,14 +37,6 @@ interface WriterInterface */ public function addRow(Row $row); - /** - * Write given data to the output with a closure function. New data will be appended to the end of the stream. - * - * @param \Closure $callback A callback returning a Row object. A new Row object is injected into the callback. - * @return WriterInterface - */ - public function withRow(\Closure $callback); - /** * Write a given array of rows to the output. New data will be appended to the end of the stream. * diff --git a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php index d55a00d..341fbf6 100644 --- a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php +++ b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php @@ -127,7 +127,6 @@ EOD; * @throws IOException If the data cannot be written * @throws InvalidArgumentException If a cell value's type is not supported * @return void - * @return void */ public function addRow(Worksheet $worksheet, Row $row) { @@ -145,8 +144,6 @@ EOD; * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported * @return void - * - * @return void */ private function addNonEmptyRow(Worksheet $worksheet, Row $row) { diff --git a/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php b/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php index ef58574..7d2dc5c 100644 --- a/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php +++ b/tests/Spout/Reader/XLSX/Helper/CellValueFormatterTest.php @@ -3,6 +3,7 @@ namespace Box\Spout\Reader\XLSX\Helper; use Box\Spout\Common\Helper\Escaper; +use Box\Spout\Reader\XLSX\Manager\StyleManager; /** * Class CellValueFormatterTest @@ -39,7 +40,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase */ public function testExcelDate($cellType, $nodeValue, $expectedDateAsString) { - $nodeListMock = $this->getMockBuilder('DOMNodeList')->disableOriginalConstructor()->getMock(); + $nodeListMock = $this->createMock('DOMNodeList'); $nodeListMock ->expects($this->atLeastOnce()) @@ -47,7 +48,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase ->with(0) ->will($this->returnValue((object) ['nodeValue' => $nodeValue])); - $nodeMock = $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock(); + $nodeMock = $this->createMock('DOMElement'); $nodeMock ->expects($this->atLeastOnce()) @@ -64,7 +65,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($nodeListMock)); /** @var \Box\Spout\Reader\XLSX\Manager\StyleManager|\PHPUnit_Framework_MockObject_MockObject $styleManagerMock */ - $styleManagerMock = $this->getMockBuilder('Box\Spout\Reader\XLSX\Manager\StyleManager')->disableOriginalConstructor()->getMock(); + $styleManagerMock = $this->createMock(StyleManager::class); $styleManagerMock ->expects($this->once()) @@ -120,7 +121,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase public function testFormatNumericCellValueWithNumbers($value, $expectedFormattedValue, $expectedType) { /** @var \Box\Spout\Reader\XLSX\Manager\StyleManager|\PHPUnit_Framework_MockObject_MockObject $styleManagerMock */ - $styleManagerMock = $this->getMockBuilder('Box\Spout\Reader\XLSX\Manager\StyleManager')->disableOriginalConstructor()->getMock(); + $styleManagerMock = $this->createMock(StyleManager::class); $styleManagerMock ->expects($this->once()) ->method('shouldFormatNumericValueAsDate') @@ -155,14 +156,14 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase */ public function testFormatInlineStringCellValue($value, $expectedFormattedValue) { - $nodeListMock = $this->getMockBuilder('DOMNodeList')->disableOriginalConstructor()->getMock(); + $nodeListMock = $this->createMock('DOMNodeList'); $nodeListMock ->expects($this->atLeastOnce()) ->method('item') ->with(0) ->will($this->returnValue((object) ['nodeValue' => $value])); - $nodeMock = $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock(); + $nodeMock = $this->createMock('DOMElement'); $nodeMock ->expects($this->atLeastOnce()) ->method('getElementsByTagName') diff --git a/tests/Spout/Writer/CSV/WriterTest.php b/tests/Spout/Writer/CSV/WriterTest.php index 824584d..d8e4dad 100644 --- a/tests/Spout/Writer/CSV/WriterTest.php +++ b/tests/Spout/Writer/CSV/WriterTest.php @@ -6,7 +6,6 @@ use Box\Spout\Common\Helper\EncodingHelper; use Box\Spout\Common\Type; use Box\Spout\TestUsingResource; use Box\Spout\Writer\Common\Creator\EntityFactory; -use Box\Spout\Writer\Common\Entity\Cell; use Box\Spout\Writer\WriterFactory; /** @@ -28,8 +27,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase $writer = WriterFactory::create(Type::CSV); @$writer->openToFile($filePath); $row = EntityFactory::createRow([ - new Cell('csv--11'), - new Cell('csv--12'), + EntityFactory::createCell('csv--11'), + EntityFactory::createCell('csv--12'), ]); $writer->addRow($row); $writer->close(); @@ -42,8 +41,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::CSV); $row = EntityFactory::createRow([ - new Cell('csv--11'), - new Cell('csv--12'), + EntityFactory::createCell('csv--11'), + EntityFactory::createCell('csv--12'), ]); $writer->addRow($row); $writer->close(); @@ -56,8 +55,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::CSV); $row = EntityFactory::createRow([ - new Cell('csv--11'), - new Cell('csv--12'), + EntityFactory::createCell('csv--11'), + EntityFactory::createCell('csv--12'), ]); $writer->addRows([$row]); $writer->close(); @@ -196,7 +195,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase public function testWriteShouldAcceptCellObjects() { $allRows = [ - [new Cell('String Value'), new Cell(1)], + [EntityFactory::createCell('String Value'), EntityFactory::createCell(1)], ]; $writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_cell_objects.csv'); $writtenContent = $this->trimWrittenContent($writtenContent); @@ -225,12 +224,11 @@ class WriterTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $writer->addRows(array_map(function ($oneRow) { - $row = EntityFactory::createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows)); + $writer->close(); return file_get_contents($resourcePath); diff --git a/tests/Spout/Writer/Common/Entity/CellTest.php b/tests/Spout/Writer/Common/Entity/CellTest.php index a0cb9ea..e31a0b2 100644 --- a/tests/Spout/Writer/Common/Entity/CellTest.php +++ b/tests/Spout/Writer/Common/Entity/CellTest.php @@ -2,54 +2,65 @@ namespace Box\Spout\Writer\Common\Entity; +use Box\Spout\Writer\Common\Entity\Style\Style; use PHPUnit\Framework\TestCase; class CellTest extends TestCase { - protected function styleMock() - { - $styleMock = $this - ->getMockBuilder('Box\Spout\Writer\Common\Entity\Style\Style'); - - return $styleMock; - } - + /** + * @return void + */ public function testValidInstance() { - $this->assertInstanceOf('Box\Spout\Writer\Common\Entity\Cell', new Cell('cell')); - $this->assertInstanceOf( - 'Box\Spout\Writer\Common\Entity\Cell', - new Cell('cell-with-style', $this->styleMock()->getMock()) - ); + $this->assertInstanceOf(Cell::class, new Cell('cell')); + $this->assertInstanceOf(Cell::class, new Cell('cell-with-style', $this->createMock(Style::class))); } + /** + * @return void + */ public function testCellTypeNumeric() { $this->assertTrue((new Cell(0))->isNumeric()); $this->assertTrue((new Cell(1))->isNumeric()); } + /** + * @return void + */ public function testCellTypeString() { $this->assertTrue((new Cell('String!'))->isString()); } + /** + * @return void + */ public function testCellTypeEmptyString() { $this->assertTrue((new Cell(''))->isEmpty()); } + /** + * @return void + */ public function testCellTypeEmptyNull() { $this->assertTrue((new Cell(null))->isEmpty()); } + /** + * @return void + */ public function testCellTypeBool() { $this->assertTrue((new Cell(true))->isBoolean()); $this->assertTrue((new Cell(false))->isBoolean()); } + /** + * @return void + */ public function testCellTypeError() { $this->assertTrue((new Cell([]))->isError()); diff --git a/tests/Spout/Writer/Common/Entity/RowTest.php b/tests/Spout/Writer/Common/Entity/RowTest.php index 9406c90..ff9a1c7 100644 --- a/tests/Spout/Writer/Common/Entity/RowTest.php +++ b/tests/Spout/Writer/Common/Entity/RowTest.php @@ -2,88 +2,113 @@ namespace Box\Spout\Writer\Common\Entity; +use Box\Spout\Writer\Common\Entity\Style\Style; +use Box\Spout\Writer\Common\Manager\RowManager; use PHPUnit\Framework\TestCase; class RowTest extends TestCase { - protected function styleMock() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|Style + */ + private function getStyleMock() { - $styleMock = $this - ->getMockBuilder('Box\Spout\Writer\Common\Entity\Style\Style'); - - return $styleMock; + return $this->createMock(Style::class); } - protected function cellMock() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|Cell + */ + private function getCellMock() { - $cellMock = $this - ->getMockBuilder('Box\Spout\Writer\Common\Entity\Cell') - ->disableOriginalConstructor(); - - return $cellMock; + return $this->createMock(Cell::class); } - protected function rowManagerMock() + /** + * @return \PHPUnit_Framework_MockObject_MockObject|RowManager + */ + private function getRowManagerMock() { - $rowManagerMock = $this - ->getMockBuilder('Box\Spout\Writer\Common\Manager\RowManager') - ->disableOriginalConstructor(); - - return $rowManagerMock; + return $this->createMock(RowManager::class); } + /** + * @return void + */ public function testValidInstance() { $this->assertInstanceOf( - 'Box\Spout\Writer\Common\Entity\Row', - new Row( - [], - null, - $this->rowManagerMock()->getMock() - ) + Row::class, + new Row([], null, $this->getRowManagerMock()) ); } + /** + * @return void + */ public function testSetCells() { - $o = new Row([], null, $this->rowManagerMock()->getMock()); - $o->setCells([$this->cellMock()->getMock(), $this->cellMock()->getMock()]); - $this->assertEquals(2, count($o->getCells())); + $row = new Row([], null, $this->getRowManagerMock()); + $row->setCells([$this->getCellMock(), $this->getCellMock()]); + + $this->assertEquals(2, count($row->getCells())); } + /** + * @return void + */ public function testSetCellsResets() { - $o = new Row([], null, $this->rowManagerMock()->getMock()); - $o->setCells([$this->cellMock()->getMock(), $this->cellMock()->getMock()]); - $this->assertEquals(2, count($o->getCells())); - $o->setCells([$this->cellMock()->getMock()]); - $this->assertEquals(1, count($o->getCells())); + $row = new Row([], null, $this->getRowManagerMock()); + $row->setCells([$this->getCellMock(), $this->getCellMock()]); + + $this->assertEquals(2, count($row->getCells())); + + $row->setCells([$this->getCellMock()]); + + $this->assertEquals(1, count($row->getCells())); } + /** + * @return void + */ public function testGetCells() { - $o = new Row([], null, $this->rowManagerMock()->getMock()); - $this->assertEquals(0, count($o->getCells())); - $o->setCells([$this->cellMock()->getMock(), $this->cellMock()->getMock()]); - $this->assertEquals(2, count($o->getCells())); + $row = new Row([], null, $this->getRowManagerMock()); + + $this->assertEquals(0, count($row->getCells())); + + $row->setCells([$this->getCellMock(), $this->getCellMock()]); + + $this->assertEquals(2, count($row->getCells())); } + /** + * @return void + */ public function testAddCell() { - $o = new Row([], null, $this->rowManagerMock()->getMock()); - $o->setCells([$this->cellMock()->getMock(), $this->cellMock()->getMock()]); - $this->assertEquals(2, count($o->getCells())); - $o->addCell($this->cellMock()->getMock()); - $this->assertEquals(3, count($o->getCells())); + $row = new Row([], null, $this->getRowManagerMock()); + $row->setCells([$this->getCellMock(), $this->getCellMock()]); + + $this->assertEquals(2, count($row->getCells())); + + $row->addCell($this->getCellMock()); + + $this->assertEquals(3, count($row->getCells())); } + /** + * @return void + */ public function testFluentInterface() { - $o = new Row([], null, $this->rowManagerMock()->getMock()); - $o - ->addCell($this->cellMock()->getMock()) - ->setStyle($this->styleMock()->getMock()) + $row = new Row([], null, $this->getRowManagerMock()); + $row + ->addCell($this->getCellMock()) + ->setStyle($this->getStyleMock()) ->setCells([]); - $this->assertTrue(is_object($o)); + + $this->assertTrue(is_object($row)); } } diff --git a/tests/Spout/Writer/Common/Manager/CellManagerTest.php b/tests/Spout/Writer/Common/Manager/CellManagerTest.php new file mode 100644 index 0000000..f10eefd --- /dev/null +++ b/tests/Spout/Writer/Common/Manager/CellManagerTest.php @@ -0,0 +1,28 @@ +assertFalse($cell->getStyle()->isFontBold()); + + $style = (new StyleBuilder())->setFontBold()->build(); + $cellManager->applyStyle($cell, $style); + + $this->assertTrue($cell->getStyle()->isFontBold()); + } +} diff --git a/tests/Spout/Writer/Common/Manager/RowManagerTest.php b/tests/Spout/Writer/Common/Manager/RowManagerTest.php index 3e7bd58..93c6844 100644 --- a/tests/Spout/Writer/Common/Manager/RowManagerTest.php +++ b/tests/Spout/Writer/Common/Manager/RowManagerTest.php @@ -2,6 +2,7 @@ namespace Spout\Writer\Common\Manager; +use Box\Spout\Writer\Common\Creator\Style\StyleBuilder; use Box\Spout\Writer\Common\Entity\Cell; use Box\Spout\Writer\Common\Entity\Row; use Box\Spout\Writer\Common\Manager\RowManager; @@ -11,31 +12,75 @@ use PHPUnit\Framework\TestCase; class RowManagerTest extends TestCase { /** - * @var RowManager + * @return void */ - protected $rowManager; - - public function setUp() + public function testApplyStyle() { - $this->rowManager = new RowManager(new StyleMerger()); - parent::setUp(); + $rowManager = new RowManager(new StyleMerger()); + $row = new Row([new Cell('test')], null, $rowManager); + + $this->assertFalse($row->getStyle()->isFontBold()); + + $style = (new StyleBuilder())->setFontBold()->build(); + $rowManager->applyStyle($row, $style); + + $this->assertTrue($row->getStyle()->isFontBold()); } - public function testIsEmptyRow() + /** + * @return array + */ + public function dataProviderForTestHasCells() { - $row = new Row([], null, $this->rowManager); - $this->assertTrue($this->rowManager->isEmpty($row)); + return [ + // cells, expected hasCells + [[], false], + [[new Cell('')], true], + [[new Cell(null)], true], + [[new Cell('test')], true], + ]; + } - $row = new Row([ - new Cell(''), - ], null, $this->rowManager); - $this->assertTrue($this->rowManager->isEmpty($row)); + /** + * @dataProvider dataProviderForTestHasCells + * + * @param array $cells + * @param bool $expectedHasCells + * @return void + */ + public function testHasCells(array $cells, $expectedHasCells) + { + $rowManager = new RowManager(new StyleMerger()); - $row = new Row([ - new Cell(''), - new Cell(''), - new Cell('Okay'), - ], null, $this->rowManager); - $this->assertFalse($this->rowManager->isEmpty($row)); + $row = new Row($cells, null, $rowManager); + $this->assertEquals($expectedHasCells, $rowManager->hasCells($row)); + } + + /** + * @return array + */ + public function dataProviderForTestIsEmptyRow() + { + return [ + // cells, expected isEmpty + [[], true], + [[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 = new RowManager(new StyleMerger()); + + $row = new Row($cells, null, $rowManager); + $this->assertEquals($expectedIsEmpty, $rowManager->isEmpty($row)); } } diff --git a/tests/Spout/Writer/ODS/SheetTest.php b/tests/Spout/Writer/ODS/SheetTest.php index e09c028..4401915 100644 --- a/tests/Spout/Writer/ODS/SheetTest.php +++ b/tests/Spout/Writer/ODS/SheetTest.php @@ -5,7 +5,6 @@ namespace Box\Spout\Writer\ODS; use Box\Spout\Common\Type; use Box\Spout\TestUsingResource; use Box\Spout\Writer\Common\Creator\EntityFactory; -use Box\Spout\Writer\Common\Entity\Cell; use Box\Spout\Writer\Common\Entity\Sheet; use Box\Spout\Writer\WriterFactory; @@ -94,8 +93,8 @@ class SheetTest extends \PHPUnit_Framework_TestCase $sheet->setName($sheetName); $row = EntityFactory::createRow([ - new Cell('ods--11'), - new Cell('ods--12'), + EntityFactory::createCell('ods--11'), + EntityFactory::createCell('ods--12'), ]); $writer->addRow($row); $writer->close(); @@ -115,17 +114,17 @@ class SheetTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $row = EntityFactory::createRow([ - new Cell('ods--sheet1--11'), - new Cell('ods--sheet1--12'), + EntityFactory::createCell('ods--sheet1--11'), + EntityFactory::createCell('ods--sheet1--12'), ]); $writer->addRow($row); $writer->addNewSheetAndMakeItCurrent(); $row = EntityFactory::createRow([ - new Cell('ods--sheet2--11'), - new Cell('ods--sheet2--12'), - new Cell('ods--sheet2--13'), + EntityFactory::createCell('ods--sheet2--11'), + EntityFactory::createCell('ods--sheet2--12'), + EntityFactory::createCell('ods--sheet2--13'), ]); $writer->addRow($row); diff --git a/tests/Spout/Writer/ODS/WriterTest.php b/tests/Spout/Writer/ODS/WriterTest.php index d0091fd..19e1d08 100644 --- a/tests/Spout/Writer/ODS/WriterTest.php +++ b/tests/Spout/Writer/ODS/WriterTest.php @@ -52,8 +52,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::ODS); $row = $this->entityFactory->createRow([ - new Cell('csv--11'), - new Cell('csv--12'), + EntityFactory::createCell('csv--11'), + EntityFactory::createCell('csv--12'), ]); $writer->addRow($row); } @@ -65,8 +65,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::ODS); $row = $this->entityFactory->createRow([ - new Cell('csv--11'), - new Cell('csv--12'), + EntityFactory::createCell('csv--11'), + EntityFactory::createCell('csv--12'), ]); $writer->addRows([$row]); } @@ -339,11 +339,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $arrayToRows = function (array $allRows) { return array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { - return new Cell($value); + return $this->entityFactory->createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows); }; @@ -505,8 +503,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_writer_should_accept_cell_objects.ods'; $dataRows = [ - [new Cell('ods--11'), new Cell('ods--12')], - [new Cell('ods--21'), new Cell('ods--22'), new Cell('ods--23')], + [EntityFactory::createCell('ods--11'), EntityFactory::createCell('ods--12')], + [EntityFactory::createCell('ods--21'), EntityFactory::createCell('ods--22'), EntityFactory::createCell('ods--23')], ]; $this->writeToODSFile($dataRows, $fileName); @@ -526,7 +524,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_writer_should_accept_cell_objects_with_types.ods'; $dataRows = [ - [new Cell('i am a string'), new Cell(51465), new Cell(true), new Cell(51465.5)], + [EntityFactory::createCell('i am a string'), EntityFactory::createCell(51465), EntityFactory::createCell(true), EntityFactory::createCell(51465.5)], ]; $this->writeToODSFile($dataRows, $fileName); @@ -556,15 +554,14 @@ class WriterTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $writer->addRows(array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { + return $this->entityFactory->createRow(array_map(function ($value) { + // @TODO: always pass a Cell instance! if (!$value instanceof Cell) { - return new Cell($value); + return EntityFactory::createCell($value); } else { return $value; } }, $oneRow)); - - return $row; }, $allRows)); $writer->close(); @@ -589,21 +586,17 @@ class WriterTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $writer->addRows(array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { - return new Cell($value); + return $this->entityFactory->createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows)); for ($i = 1; $i < $numSheets; $i++) { $writer->addNewSheetAndMakeItCurrent(); $writer->addRows(array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { - return new Cell($value); + return $this->entityFactory->createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows)); } diff --git a/tests/Spout/Writer/ODS/WriterWithStyleTest.php b/tests/Spout/Writer/ODS/WriterWithStyleTest.php index 0ec66ef..01aec50 100644 --- a/tests/Spout/Writer/ODS/WriterWithStyleTest.php +++ b/tests/Spout/Writer/ODS/WriterWithStyleTest.php @@ -39,8 +39,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::ODS); $row = EntityFactory::createRow([ - new Cell('ods--11'), - new Cell('ods--12'), + EntityFactory::createCell('ods--11'), + EntityFactory::createCell('ods--12'), ], $this->defaultStyle); $writer->addRow($row); } @@ -52,8 +52,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::ODS); $row = EntityFactory::createRow([ - new Cell('ods--11'), - new Cell('ods--12'), + EntityFactory::createCell('ods--11'), + EntityFactory::createCell('ods--12'), ], $this->defaultStyle); $writer->addRows([$row]); } @@ -70,17 +70,14 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase } /** + * @requires PHP 7 * @dataProvider dataProviderForInvalidStyle * * @param \Box\Spout\Writer\Common\Entity\Style\Style $style */ public function testAddRowWithStyleShouldThrowExceptionIfInvalidStyleGiven($style) { - if (version_compare(PHP_VERSION, '7.0.0') >= 0) { - $this->expectException(\TypeError::class); - } else { - $this->markTestSkipped('PHP > 7.0 only'); - } + $this->expectException(\TypeError::class); $fileName = 'test_add_row_with_style_should_throw_exception.ods'; $this->createGeneratedFolderIfNeeded($fileName); @@ -89,24 +86,21 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $writer = WriterFactory::create(Type::ODS); $writer->openToFile($resourcePath); $row = EntityFactory::createRow([ - new Cell('ods--11'), - new Cell('ods--12'), + EntityFactory::createCell('ods--11'), + EntityFactory::createCell('ods--12'), ], $style); $writer->addRow($row); } /** + * @requires PHP 7 * @dataProvider dataProviderForInvalidStyle * * @param \Box\Spout\Writer\Common\Entity\Style\Style $style */ public function testAddRowsWithStyleShouldThrowExceptionIfInvalidStyleGiven($style) { - if (version_compare(PHP_VERSION, '7.0.0') >= 0) { - $this->expectException(\TypeError::class); - } else { - $this->markTestSkipped('PHP > 7.0 only'); - } + $this->expectException(\TypeError::class); $fileName = 'test_add_row_with_style_should_throw_exception.ods'; $this->createGeneratedFolderIfNeeded($fileName); @@ -115,8 +109,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $writer = WriterFactory::create(Type::ODS); $writer->openToFile($resourcePath); $row = EntityFactory::createRow([ - new Cell('ods--11'), - new Cell('ods--12'), + EntityFactory::createCell('ods--11'), + EntityFactory::createCell('ods--12'), ], $style); $writer->addRows([[$row]]); } @@ -356,7 +350,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_set_default_row_style.ods'; $row = EntityFactory::createRow([ - new Cell('ods--11'), + EntityFactory::createCell('ods--11'), ]); $dataRows = [$row]; @@ -379,11 +373,9 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $arrayToRows = function (array $allRows) use ($style) { return array_map(function ($oneRow) use ($style) { - $row = EntityFactory::createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow), $style); - - return $row; }, $allRows); }; @@ -444,7 +436,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $currentRow = $allRows[$i]; $currentStyle = $styles[$i]; $row = EntityFactory::createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createCell($value); }, $currentRow), $currentStyle); $writer->addRow($row); } diff --git a/tests/Spout/Writer/XLSX/SheetTest.php b/tests/Spout/Writer/XLSX/SheetTest.php index 83d874f..6e0c435 100644 --- a/tests/Spout/Writer/XLSX/SheetTest.php +++ b/tests/Spout/Writer/XLSX/SheetTest.php @@ -5,7 +5,6 @@ namespace Box\Spout\Writer\XLSX; use Box\Spout\Common\Type; use Box\Spout\TestUsingResource; use Box\Spout\Writer\Common\Creator\EntityFactory; -use Box\Spout\Writer\Common\Entity\Cell; use Box\Spout\Writer\Common\Entity\Sheet; use Box\Spout\Writer\WriterFactory; @@ -94,8 +93,8 @@ class SheetTest extends \PHPUnit_Framework_TestCase $sheet->setName($sheetName); $row = EntityFactory::createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ]); $writer->addRow($row); $writer->close(); @@ -117,17 +116,17 @@ class SheetTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $row = EntityFactory::createRow([ - new Cell('xlsx--sheet1--11'), - new Cell('xlsx--sheet1--12'), + EntityFactory::createCell('xlsx--sheet1--11'), + EntityFactory::createCell('xlsx--sheet1--12'), ]); $writer->addRow($row); $writer->addNewSheetAndMakeItCurrent(); $row = EntityFactory::createRow([ - new Cell('xlsx--sheet2--11'), - new Cell('xlsx--sheet2--12'), - new Cell('xlsx--sheet2--13'), + EntityFactory::createCell('xlsx--sheet2--11'), + EntityFactory::createCell('xlsx--sheet2--12'), + EntityFactory::createCell('xlsx--sheet2--13'), ]); $writer->addRow($row); diff --git a/tests/Spout/Writer/XLSX/WriterTest.php b/tests/Spout/Writer/XLSX/WriterTest.php index 2e27e56..ebf04c1 100644 --- a/tests/Spout/Writer/XLSX/WriterTest.php +++ b/tests/Spout/Writer/XLSX/WriterTest.php @@ -51,9 +51,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::XLSX); - $row = $this->entityFactory->createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + $row = EntityFactory::createRow([ + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ]); $writer->addRow($row); } @@ -64,9 +64,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase public function testAddRowShouldThrowExceptionIfCalledBeforeOpeningWriter() { $writer = WriterFactory::create(Type::XLSX); - $row = $this->entityFactory->createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + $row = EntityFactory::createRow([ + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ]); $writer->addRows([$row]); } @@ -344,7 +344,6 @@ class WriterTest extends \PHPUnit_Framework_TestCase */ public function testAddRowShouldNotWriteEmptyRows() { - $this->markTestIncomplete('Unsure why this does not pass'); $fileName = 'test_add_row_should_not_write_empty_rows.xlsx'; $dataRows = [ [''], @@ -388,11 +387,9 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $arrayToRows = function (array $allRows) { return array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows); }; @@ -548,8 +545,8 @@ class WriterTest extends \PHPUnit_Framework_TestCase { $fileName = 'test_writer_should_accept_cell_objects.xlsx'; $dataRows = [ - [new Cell('xlsx--11'), new Cell('xlsx--12')], - [new Cell('xlsx--21'), new Cell('xlsx--22'), new Cell('xlsx--23')], + [EntityFactory::createCell('xlsx--11'), EntityFactory::createCell('xlsx--12')], + [EntityFactory::createCell('xlsx--21'), EntityFactory::createCell('xlsx--22'), EntityFactory::createCell('xlsx--23')], ]; $this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false); @@ -570,10 +567,10 @@ class WriterTest extends \PHPUnit_Framework_TestCase $fileName = 'test_writer_should_accept_cell_objects_with_types.xlsx'; $dataRowsShared = [ - [new Cell('i am a string')], + [EntityFactory::createCell('i am a string')], ]; $dataRowsInline = [ - [new Cell(51465), new Cell(true), new Cell(51465.5)], + [EntityFactory::createCell(51465), EntityFactory::createCell(true), EntityFactory::createCell(51465.5)], ]; $dataRows = array_merge($dataRowsShared, $dataRowsInline); @@ -614,15 +611,13 @@ class WriterTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $writer->addRows(array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { + return EntityFactory::createRow(array_map(function ($value) { if (!$value instanceof Cell) { - return new Cell($value); + return EntityFactory::createCell($value); } else { return $value; } }, $oneRow)); - - return $row; }, $allRows)); $writer->close(); @@ -649,21 +644,17 @@ class WriterTest extends \PHPUnit_Framework_TestCase $writer->openToFile($resourcePath); $writer->addRows(array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows)); for ($i = 1; $i < $numSheets; $i++) { $writer->addNewSheetAndMakeItCurrent(); $writer->addRows(array_map(function ($oneRow) { - $row = $this->entityFactory->createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow)); - - return $row; }, $allRows)); } diff --git a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php index 69bff01..d321bbb 100644 --- a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php +++ b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php @@ -41,8 +41,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::XLSX); $row = EntityFactory::createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ], $this->defaultStyle); $writer->addRow($row); } @@ -54,8 +54,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $writer = WriterFactory::create(Type::XLSX); $row = EntityFactory::createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ], $this->defaultStyle); $writer->addRows([$row]); } @@ -72,17 +72,14 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase } /** + * @requires PHP 7 * @dataProvider dataProviderForInvalidStyle * * @param \Box\Spout\Writer\Common\Entity\Style\Style $style */ public function testAddRowWithStyleShouldThrowExceptionIfInvalidStyleGiven($style) { - if (version_compare(PHP_VERSION, '7.0.0') >= 0) { - $this->expectException(\TypeError::class); - } else { - $this->markTestSkipped('PHP > 7.0 only'); - } + $this->expectException(\TypeError::class); $fileName = 'test_add_row_with_style_should_throw_exception.xlsx'; $this->createGeneratedFolderIfNeeded($fileName); @@ -91,24 +88,21 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $writer = WriterFactory::create(Type::XLSX); $writer->openToFile($resourcePath); $row = EntityFactory::createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ], $style); $writer->addRow($row); } /** + * @requires PHP 7 * @dataProvider dataProviderForInvalidStyle * * @param \Box\Spout\Writer\Common\Entity\Style\Style $style */ public function testAddRowsWithStyleShouldThrowExceptionIfInvalidStyleGiven($style) { - if (version_compare(PHP_VERSION, '7.0.0') >= 0) { - $this->expectException(\TypeError::class); - } else { - $this->markTestSkipped('PHP > 7.0 only'); - } + $this->expectException(\TypeError::class); $fileName = 'test_add_row_with_style_should_throw_exception.xlsx'; $this->createGeneratedFolderIfNeeded($fileName); @@ -117,8 +111,8 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $writer = WriterFactory::create(Type::XLSX); $writer->openToFile($resourcePath); $row = EntityFactory::createRow([ - new Cell('xlsx--11'), - new Cell('xlsx--12'), + EntityFactory::createCell('xlsx--11'), + EntityFactory::createCell('xlsx--12'), ], $style); $writer->addRows([$row]); } @@ -458,7 +452,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $fileName = 'test_set_default_row_style.xlsx'; $row = EntityFactory::createRow([ - new Cell('xlsx--11'), + EntityFactory::createCell('xlsx--11'), ]); $dataRows = [$row]; @@ -554,11 +548,9 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase { $arrayToRows = function (array $allRows) use ($style) { return array_map(function ($oneRow) use ($style) { - $row = EntityFactory::createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createRow(array_map(function ($value) { + return EntityFactory::createCell($value); }, $oneRow), $style); - - return $row; }, $allRows); }; @@ -622,7 +614,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase $currentRow = $allRows[$i]; $currentStyle = $styles[$i]; $row = EntityFactory::createRow(array_map(function ($value) { - return new Cell($value); + return EntityFactory::createCell($value); }, $currentRow), $currentStyle); $writer->addRow($row); }