Consolidate external EntityFactory

All entities will now be created through a single factory (including the Writers).
Also, added a EntityFactory::createRowFromArray() to make it easier to create rows
This commit is contained in:
Adrien Loison committed 2017-11-05 13:18:29 +01:00
1 parent 2d2151ac8d
commit 3d0f108b1d
12 files changed
+201 -170

No files matched your search

+14 -14
View File
@@ -7,11 +7,11 @@ use Box\Spout\Common\Exception\IOException;
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\Entity\Row;
use Box\Spout\Writer\Exception\WriterAlreadyOpenedException;
use Box\Spout\Writer\Exception\WriterNotOpenedException;
use Box\Spout\Writer\RowCreationHelper;
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Writer\XLSX\Manager\WorksheetManager;
/**
@@ -33,7 +33,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$this->createUnwritableFolderIfNeeded();
$filePath = $this->getGeneratedUnwritableResourcePath($fileName);
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
@$writer->openToFile($filePath);
}
@@ -44,7 +44,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
{
$this->expectException(WriterNotOpenedException::class);
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->addRow($this->createRowFromValues(['xlsx--11', 'xlsx--12']));
}
@@ -55,7 +55,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
{
$this->expectException(WriterNotOpenedException::class);
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->addRows($this->createRowsFromValues([['xlsx--11', 'xlsx--12']]));
}
@@ -70,7 +70,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$filePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->openToFile($filePath);
$writer->setTempFolder('');
@@ -87,7 +87,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$filePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->openToFile($filePath);
$writer->setShouldUseInlineStrings(true);
@@ -104,7 +104,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$filePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->openToFile($filePath);
$writer->setShouldCreateNewSheetsAutomatically(true);
@@ -158,7 +158,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$tempFolderPath = $this->getTempFolderPath();
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->setTempFolder($tempFolderPath);
$writer->openToFile($resourcePath);
@@ -183,7 +183,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->openToFile($resourcePath);
$writer->addNewSheetAndMakeItCurrent();
$writer->close();
@@ -203,7 +203,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->openToFile($resourcePath);
$writer->addNewSheetAndMakeItCurrent();
@@ -226,7 +226,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName);
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->close(); // This call should not cause any error
$writer->openToFile($resourcePath);
@@ -403,7 +403,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->setShouldUseInlineStrings(true);
$writer->openToFile($resourcePath);
@@ -543,7 +543,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->setShouldUseInlineStrings($shouldUseInlineStrings);
$writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically);
@@ -568,7 +568,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX);
$writer = EntityFactory::createWriter(Type::XLSX);
$writer->setShouldUseInlineStrings($shouldUseInlineStrings);
$writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically);