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:
1 parent
2d2151ac8d
commit
3d0f108b1d
12 files changed
+201
-170
No files matched your search
@@ -4,10 +4,10 @@ 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\Sheet;
|
||||
use Box\Spout\Writer\Exception\InvalidSheetNameException;
|
||||
use Box\Spout\Writer\RowCreationHelper;
|
||||
use Box\Spout\Writer\WriterFactory;
|
||||
|
||||
/**
|
||||
* Class SheetTest
|
||||
@@ -65,7 +65,7 @@ class SheetTest 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);
|
||||
|
||||
$customSheetName = 'Sheet name';
|
||||
@@ -89,7 +89,7 @@ class SheetTest 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);
|
||||
|
||||
$sheet = $writer->getCurrentSheet();
|
||||
@@ -111,7 +111,7 @@ class SheetTest 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->addRow($this->createRowFromValues(['xlsx--sheet1--11', 'xlsx--sheet1--12']));
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Box\Spout\Writer\XLSX;
|
||||
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\Style\BorderBuilder;
|
||||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||
use Box\Spout\Writer\Common\Entity\Row;
|
||||
@@ -14,7 +15,6 @@ use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
|
||||
use Box\Spout\Writer\Exception\WriterNotOpenedException;
|
||||
use Box\Spout\Writer\RowCreationHelper;
|
||||
use Box\Spout\Writer\WriterFactory;
|
||||
use Box\Spout\Writer\XLSX\Manager\OptionsManager;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->expectException(WriterNotOpenedException::class);
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer = EntityFactory::createWriter(Type::XLSX);
|
||||
$writer->addRow($this->createStyledRowFromValues(['xlsx--11', 'xlsx--12'], $this->defaultStyle));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->expectException(WriterNotOpenedException::class);
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer = EntityFactory::createWriter(Type::XLSX);
|
||||
$writer->addRow($this->createStyledRowFromValues(['xlsx--11', 'xlsx--12'], $this->defaultStyle));
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ class WriterWithStyleTest 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);
|
||||
@@ -513,7 +513,7 @@ class WriterWithStyleTest 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->setDefaultRowStyle($defaultStyle);
|
||||
|
||||
|
||||
Reference in new issue
Block a user