make tests pass again

This commit is contained in:
madflow 2017-09-29 14:47:33 +02:00
parent 6971a793ef
commit 2797052c54
12 changed files with 44 additions and 113 deletions

View File

@ -8,7 +8,9 @@ use Box\Spout\Writer\Common\Entity\Sheet;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Entity\Workbook;
use Box\Spout\Writer\Common\Entity\Worksheet;
use Box\Spout\Writer\Common\Manager\RowManager;
use Box\Spout\Writer\Common\Manager\SheetManager;
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
/**
* Class EntityFactory
@ -49,7 +51,7 @@ class EntityFactory
* @param mixed $cellValue
* @return Cell
*/
public function createCell($cellValue)
public static function createCell($cellValue)
{
return new Cell($cellValue);
}
@ -67,9 +69,10 @@ class EntityFactory
* @param Style|null $style
* @return Row
*/
public function createRow(array $cells, Style $style = null)
public static function createRow(array $cells, Style $style = null)
{
$rowManager = $this->managerFactory->createRowManager();
$styleMerger = new StyleMerger();
$rowManager = new RowManager($styleMerger);
return new Row($cells, $style, $rowManager);
}
}

View File

@ -7,17 +7,14 @@ use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
use Box\Spout\Writer\Common\Entity\Options;
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Sheet;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Entity\Workbook;
use Box\Spout\Writer\Common\Entity\Worksheet;
use Box\Spout\Writer\Common\Helper\FileSystemWithRootFolderHelperInterface;
use Box\Spout\Writer\Common\Manager\Style\StyleManagerInterface;
use Box\Spout\Writer\Exception\SheetNotFoundException;
use Box\Spout\Writer\Exception\WriterException;
use Box\Spout\Writer\Common\Creator\EntityFactory;
/**
* Class WorkbookManagerAbstract

View File

@ -4,10 +4,10 @@ namespace Box\Spout\Writer\ODS\Manager;
use Box\Spout\Common\Exception\InvalidArgumentException;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\Escaper\ODS as ODSEscaper;
use Box\Spout\Common\Helper\StringHelper;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Worksheet;
use Box\Spout\Writer\Common\Manager\WorksheetManagerInterface;
@ -25,34 +25,23 @@ class WorksheetManager implements WorksheetManagerInterface
/** @var StringHelper String helper */
private $stringHelper;
/** @var EntityFactory Factory to create entities */
private $entityFactory;
/** @var StyleManager Manages styles */
private $styleManager;
/**
* WorksheetManager constructor.
*
* @param \Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper
* @param StyleManager $styleManager
* @param \Box\Spout\Common\Escaper\ODS $stringsEscaper
* @param ODSEscaper $stringsEscaper
* @param StringHelper $stringHelper
* @param EntityFactory $entityFactory
*/
public function __construct(
StyleManager $styleManager,
\Box\Spout\Common\Escaper\ODS $stringsEscaper,
ODSEscaper $stringsEscaper,
StringHelper $stringHelper)
{
\Box\Spout\Common\Helper\Escaper\ODS $stringsEscaper,
StringHelper $stringHelper,
EntityFactory $entityFactory
) {
$this->stringsEscaper = $stringsEscaper;
$this->stringHelper = $stringHelper;
$this->styleManager = $styleManager;
$this->entityFactory = $entityFactory;
}
/**

View File

@ -7,6 +7,7 @@ use Box\Spout\Common\Exception\InvalidArgumentException;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Exception\SpoutException;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Writer\Common\Entity\Options;
@ -63,8 +64,6 @@ abstract class WriterAbstract implements WriterInterface
$this->styleMerger = $styleMerger;
$this->globalFunctionsHelper = $globalFunctionsHelper;
$this->helperFactory = $helperFactory;
$this->resetRowStyleToDefault();
}
/**
@ -210,7 +209,7 @@ abstract class WriterAbstract implements WriterInterface
*/
public function withRow(\Closure $callback)
{
return $this->addRow($callback(new Row()));
return $this->addRow($callback(EntityFactory::createRow([])));
}
/**

View File

@ -2,6 +2,7 @@
namespace Box\Spout\Writer;
use Box\Spout\Common\Creator\HelperFactory;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;

View File

@ -17,17 +17,6 @@ class WriterTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
/**
* @var EntityFactory
*/
protected $entityFactory;
protected function setUp()
{
$this->entityFactory = new EntityFactory(new ManagerFactory());
parent::setUp();
}
/**
* @expectedException \Box\Spout\Common\Exception\IOException
*/
@ -39,7 +28,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::CSV);
@$writer->openToFile($filePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('csv--11'),
new Cell('csv--12')
]);
@ -53,7 +42,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testWriteShouldThrowExceptionIfCallAddRowBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::CSV);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('csv--11'),
new Cell('csv--12')
]);
@ -67,7 +56,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
public function testWriteShouldThrowExceptionIfCallAddRowsBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::CSV);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('csv--11'),
new Cell('csv--12')
]);
@ -237,7 +226,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$writer->openToFile($resourcePath);
$writer->addRows(array_map(function ($oneRow) {
$row = $this->entityFactory->createRow(array_map(function ($value) {
$row = EntityFactory::createRow(array_map(function ($value) {
return new Cell($value);
}, $oneRow));
return $row;

View File

@ -17,20 +17,6 @@ class SheetTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
/**
* @var EntityFactory
*/
protected $entityFactory;
/**
* @return void
*/
public function setUp()
{
$this->entityFactory = new EntityFactory(new ManagerFactory());
}
/**
* @return void
*/
@ -108,7 +94,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$sheet = $writer->getCurrentSheet();
$sheet->setName($sheetName);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--11'),
new Cell('ods--12'),
]);
@ -129,7 +115,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--sheet1--11'),
new Cell('ods--sheet1--12'),
]);
@ -137,7 +123,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$writer->addNewSheetAndMakeItCurrent();
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--sheet2--11'),
new Cell('ods--sheet2--12'),
new Cell('ods--sheet2--13'),

View File

@ -7,8 +7,6 @@ use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\ManagerFactory;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Writer\WriterFactory;
@ -30,7 +28,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
$this->entityFactory = new EntityFactory(new ManagerFactory());
$this->entityFactory = new EntityFactory();
parent::setUp();
}
@ -326,7 +324,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
if ($expectedNumTableCells === 1) {
$tableCellNode = $tableCellNodes->item(0);
$numColumnsRepeated = (int) ($tableCellNode->getAttribute('table:number-columns-repeated'));
$numColumnsRepeated = (int)($tableCellNode->getAttribute('table:number-columns-repeated'));
$this->assertEquals($expectedNumColumnsRepeated, $numColumnsRepeated);
} else {
foreach ($tableCellNodes as $tableCellNode) {
@ -340,7 +338,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
*/
public function testAddRowShouldWriteGivenDataToTheCorrectSheet()
{
$arrayToRows = function(array $allRows) {
$arrayToRows = function (array $allRows) {
return array_map(function ($oneRow) {
$row = $this->entityFactory->createRow(array_map(function ($value) {
return new Cell($value);
@ -536,7 +534,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
foreach ($dataRows as $dataRow) {
/** @var Cell $cell */
foreach ($dataRow as $cell) {
$this->assertValueWasWritten($fileName, (string) $cell->getValue(), '');
$this->assertValueWasWritten($fileName, (string)$cell->getValue(), '');
}
}
}
@ -559,7 +557,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$writer->openToFile($resourcePath);
$writer->addRows(array_map(function ($oneRow) {
$row = $this->entityFactory->createRow(array_map(function ($value) {
if(!$value instanceof Cell) {
if (!$value instanceof Cell) {
return new Cell($value);
} else {
return $value;

View File

@ -6,13 +6,10 @@ use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\ManagerFactory;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\ODS\Helper\BorderHelper;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\WriterFactory;
@ -27,17 +24,11 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
/** @var Style */
private $defaultStyle;
/**
* @var EntityFactory
*/
protected $entityFactory;
/**
* @return void
*/
public function setUp()
{
$this->entityFactory = new EntityFactory(new ManagerFactory());
$this->defaultStyle = (new StyleBuilder())->build();
}
@ -47,7 +38,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldThrowExceptionIfCallAddRowBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::ODS);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--11'),
new Cell('ods--12'),
], $this->defaultStyle);
@ -60,7 +51,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowsWithStyleShouldThrowExceptionIfCalledBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::ODS);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--11'),
new Cell('ods--12'),
], $this->defaultStyle);
@ -97,7 +88,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--11'),
new Cell('ods--12'),
], $style);
@ -124,7 +115,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::ODS);
$writer->openToFile($resourcePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--11'),
new Cell('ods--12'),
], $style);
@ -365,7 +356,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testSetDefaultRowStyle()
{
$fileName = 'test_set_default_row_style.ods';
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('ods--11')
]);
$dataRows = [$row];
@ -387,9 +378,9 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
*/
private function writeToODSFile($allRows, $fileName, $style)
{
$arrayToRows = function(array $allRows) use ($style) {
$arrayToRows = function (array $allRows) use ($style) {
return array_map(function ($oneRow) use ($style) {
$row = $this->entityFactory->createRow(array_map(function ($value) {
$row = EntityFactory::createRow(array_map(function ($value) {
return new Cell($value);
}, $oneRow), $style);
return $row;
@ -452,7 +443,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
for ($i = 0; $i < count($allRows); $i++) {
$currentRow = $allRows[$i];
$currentStyle = $styles[$i];
$row = $this->entityFactory->createRow(array_map(function ($value) {
$row = EntityFactory::createRow(array_map(function ($value) {
return new Cell($value);
}, $currentRow), $currentStyle);
$writer->addRow($row);

View File

@ -17,19 +17,6 @@ class SheetTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
/**
* @var EntityFactory
*/
protected $entityFactory;
/**
* @return void
*/
public function setUp()
{
$this->entityFactory = new EntityFactory(new ManagerFactory());
}
/**
* @return void
*/
@ -107,7 +94,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$sheet = $writer->getCurrentSheet();
$sheet->setName($sheetName);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--11'),
new Cell('xlsx--12'),
]);
@ -130,7 +117,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($resourcePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--sheet1--11'),
new Cell('xlsx--sheet1--12'),
]);
@ -138,7 +125,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$writer->addNewSheetAndMakeItCurrent();
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--sheet2--11'),
new Cell('xlsx--sheet2--12'),
new Cell('xlsx--sheet2--13'),

View File

@ -6,7 +6,6 @@ use Box\Spout\Common\Exception\SpoutException;
use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\ManagerFactory;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Writer\XLSX\Manager\WorksheetManager;
@ -28,7 +27,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
$this->entityFactory = new EntityFactory(new ManagerFactory());
$this->entityFactory = new EntityFactory();
parent::setUp();
}

View File

@ -6,11 +6,9 @@ use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\ManagerFactory;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Entity\Style\Style;
@ -28,18 +26,12 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
/** @var \Box\Spout\Writer\Common\Entity\Style\Style */
private $defaultStyle;
/**
* @var EntityFactory
*/
protected $entityFactory;
/**
* @return void
*/
public function setUp()
{
$this->defaultStyle = (new StyleBuilder())->build();
$this->entityFactory = new EntityFactory(new ManagerFactory());
}
/**
@ -48,7 +40,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowWithStyleShouldThrowExceptionIfCallAddRowBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::XLSX);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--11'),
new Cell('xlsx--12')
], $this->defaultStyle);
@ -61,7 +53,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
public function testAddRowsWithStyleShouldThrowExceptionIfCalledBeforeOpeningWriter()
{
$writer = WriterFactory::create(Type::XLSX);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--11'),
new Cell('xlsx--12')
], $this->defaultStyle);
@ -98,7 +90,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($resourcePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--11'),
new Cell('xlsx--12')
], $style);
@ -124,7 +116,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($resourcePath);
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--11'),
new Cell('xlsx--12')
], $style);
@ -465,7 +457,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
{
$fileName = 'test_set_default_row_style.xlsx';
$row = $this->entityFactory->createRow([
$row = EntityFactory::createRow([
new Cell('xlsx--11')
]);
$dataRows = [$row];
@ -563,7 +555,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
$arrayToRows = function(array $allRows) use ($style) {
return array_map(function ($oneRow) use ($style) {
$row = $this->entityFactory->createRow(array_map(function ($value) {
$row = EntityFactory::createRow(array_map(function ($value) {
return new Cell($value);
}, $oneRow), $style);
return $row;
@ -632,7 +624,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
for ($i = 0; $i < count($allRows); $i++) {
$currentRow = $allRows[$i];
$currentStyle = $styles[$i];
$row = $this->entityFactory->createRow(array_map(function ($value) {
$row = EntityFactory::createRow(array_map(function ($value) {
return new Cell($value);
}, $currentRow), $currentStyle);
$writer->addRow($row);