Update Writer folder structure to match Reader new structure

This commit is contained in:
Adrien Loison 2015-07-20 22:32:06 -07:00
parent c52dd7bde8
commit c672558a18
16 changed files with 81 additions and 76 deletions

View File

@ -69,7 +69,7 @@ abstract class AbstractWriter implements WriterInterface
* By using this method, the data will be written to a file. * By using this method, the data will be written to a file.
* *
* @param string $outputFilePath Path of the output file that will contain the data * @param string $outputFilePath Path of the output file that will contain the data
* @return \Box\Spout\Writer\AbstractWriter * @return AbstractWriter
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
*/ */
public function openToFile($outputFilePath) public function openToFile($outputFilePath)
@ -92,7 +92,7 @@ abstract class AbstractWriter implements WriterInterface
* @codeCoverageIgnore * @codeCoverageIgnore
* *
* @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept * @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
* @return \Box\Spout\Writer\AbstractWriter * @return AbstractWriter
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
*/ */
public function openToBrowser($outputFileName) public function openToBrowser($outputFileName)
@ -144,7 +144,7 @@ abstract class AbstractWriter implements WriterInterface
* If empty, no data is added (i.e. not even as a blank row) * If empty, no data is added (i.e. not even as a blank row)
* Example: $dataRow = ['data1', 1234, null, '', 'data5', false]; * Example: $dataRow = ['data1', 1234, null, '', 'data5', false];
* *
* @return \Box\Spout\Writer\AbstractWriter * @return AbstractWriter
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
* @throws \Box\Spout\Common\Exception\IOException If unable to write data * @throws \Box\Spout\Common\Exception\IOException If unable to write data
*/ */
@ -173,7 +173,7 @@ abstract class AbstractWriter implements WriterInterface
* ['data21', 'data22', null, false], * ['data21', 'data22', null, false],
* ]; * ];
* *
* @return \Box\Spout\Writer\AbstractWriter * @return AbstractWriter
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If this function is called before opening the writer
* @throws \Box\Spout\Common\Exception\IOException If unable to write data * @throws \Box\Spout\Common\Exception\IOException If unable to write data

View File

@ -1,16 +1,17 @@
<?php <?php
namespace Box\Spout\Writer; namespace Box\Spout\Writer\CSV;
use Box\Spout\Writer\AbstractWriter;
use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Exception\IOException;
/** /**
* Class CSV * Class Writer
* This class provides support to write data to CSV files * This class provides support to write data to CSV files
* *
* @package Box\Spout\Writer * @package Box\Spout\Writer\CSV
*/ */
class CSV extends AbstractWriter class Writer extends AbstractWriter
{ {
/** Number of rows to write before flushing */ /** Number of rows to write before flushing */
const FLUSH_THRESHOLD = 500; const FLUSH_THRESHOLD = 500;
@ -32,7 +33,7 @@ class CSV extends AbstractWriter
* Sets the field delimiter for the CSV * Sets the field delimiter for the CSV
* *
* @param string $fieldDelimiter Character that delimits fields * @param string $fieldDelimiter Character that delimits fields
* @return CSV * @return Writer
*/ */
public function setFieldDelimiter($fieldDelimiter) public function setFieldDelimiter($fieldDelimiter)
{ {
@ -44,7 +45,7 @@ class CSV extends AbstractWriter
* Sets the field enclosure for the CSV * Sets the field enclosure for the CSV
* *
* @param string $fieldEnclosure Character that enclose fields * @param string $fieldEnclosure Character that enclose fields
* @return CSV * @return Writer
*/ */
public function setFieldEnclosure($fieldEnclosure) public function setFieldEnclosure($fieldEnclosure)
{ {

View File

@ -19,7 +19,7 @@ class WriterFactory
* This creates an instance of the appropriate writer, given the type of the file to be read * This creates an instance of the appropriate writer, given the type of the file to be read
* *
* @param string $writerType Type of the writer to instantiate * @param string $writerType Type of the writer to instantiate
* @return \Box\Spout\Writer\CSV|\Box\Spout\Writer\XLSX * @return \Box\Spout\Writer\CSV\Writer|\Box\Spout\Writer\XLSX\Writer
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
*/ */
public static function create($writerType) public static function create($writerType)
@ -28,10 +28,10 @@ class WriterFactory
switch ($writerType) { switch ($writerType) {
case Type::CSV: case Type::CSV:
$writer = new CSV(); $writer = new CSV\Writer();
break; break;
case Type::XLSX: case Type::XLSX:
$writer = new XLSX(); $writer = new XLSX\Writer();
break; break;
default: default:
throw new UnsupportedTypeException('No writers supporting the given type: ' . $writerType); throw new UnsupportedTypeException('No writers supporting the given type: ' . $writerType);

View File

@ -14,7 +14,7 @@ interface WriterInterface
* By using this method, the data will be written to a file. * By using this method, the data will be written to a file.
* *
* @param string $outputFilePath Path of the output file that will contain the data * @param string $outputFilePath Path of the output file that will contain the data
* @return \Box\Spout\Writer\WriterInterface * @return WriterInterface
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
*/ */
public function openToFile($outputFilePath); public function openToFile($outputFilePath);
@ -24,7 +24,7 @@ interface WriterInterface
* By using this method, the data will be outputted directly to the browser. * By using this method, the data will be outputted directly to the browser.
* *
* @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept * @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept
* @return \Box\Spout\Writer\WriterInterface * @return WriterInterface
* @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened * @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
*/ */
public function openToBrowser($outputFileName); public function openToBrowser($outputFileName);
@ -34,7 +34,7 @@ interface WriterInterface
* *
* @param array $dataRow Array containing data to be streamed. * @param array $dataRow Array containing data to be streamed.
* Example $dataRow = ['data1', 1234, null, '', 'data5']; * Example $dataRow = ['data1', 1234, null, '', 'data5'];
* @return \Box\Spout\Writer\WriterInterface * @return WriterInterface
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yetthe writer * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yetthe writer
* @throws \Box\Spout\Common\Exception\IOException If unable to write data * @throws \Box\Spout\Common\Exception\IOException If unable to write data
*/ */
@ -48,7 +48,7 @@ interface WriterInterface
* ['data11', 12, , '', 'data13'], * ['data11', 12, , '', 'data13'],
* ['data21', 'data22', null], * ['data21', 'data22', null],
* ]; * ];
* @return \Box\Spout\Writer\WriterInterface * @return WriterInterface
* @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid * @throws \Box\Spout\Common\Exception\InvalidArgumentException If the input param is not valid
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
* @throws \Box\Spout\Common\Exception\IOException If unable to write data * @throws \Box\Spout\Common\Exception\IOException If unable to write data

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Box\Spout\Writer\Helper\XLSX; namespace Box\Spout\Writer\XLSX\Helper;
/** /**
* Class CellHelper * Class CellHelper
* This class provides helper functions when working with cells * This class provides helper functions when working with cells
* *
* @package Box\Spout\Writer\Helper\XLSX * @package Box\Spout\Writer\XLSX\Helper
*/ */
class CellHelper class CellHelper
{ {

View File

@ -1,15 +1,15 @@
<?php <?php
namespace Box\Spout\Writer\Helper\XLSX; namespace Box\Spout\Writer\XLSX\Helper;
use Box\Spout\Writer\Internal\XLSX\Worksheet; use Box\Spout\Writer\XLSX\Internal\Worksheet;
/** /**
* Class FileSystemHelper * Class FileSystemHelper
* This class provides helper functions to help with the file system operations * This class provides helper functions to help with the file system operations
* like files/folders creation & deletion for XLSX files * like files/folders creation & deletion for XLSX files
* *
* @package Box\Spout\Writer\Helper\XLSX * @package Box\Spout\Writer\XLSX\Helper
*/ */
class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper class FileSystemHelper extends \Box\Spout\Common\Helper\FileSystemHelper
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Box\Spout\Writer\Helper\XLSX; namespace Box\Spout\Writer\XLSX\Helper;
use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Exception\IOException;
@ -8,7 +8,7 @@ use Box\Spout\Common\Exception\IOException;
* Class SharedStringsHelper * Class SharedStringsHelper
* This class provides helper functions to write shared strings * This class provides helper functions to write shared strings
* *
* @package Box\Spout\Writer\Helper\XLSX * @package Box\Spout\Writer\XLSX\Helper
*/ */
class SharedStringsHelper class SharedStringsHelper
{ {

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Box\Spout\Writer\Helper\XLSX; namespace Box\Spout\Writer\XLSX\Helper;
/** /**
* Class ZipHelper * Class ZipHelper
* This class provides helper functions to create zip files * This class provides helper functions to create zip files
* *
* @package Box\Spout\Writer\Helper\XLSX * @package Box\Spout\Writer\XLSX\Helper
*/ */
class ZipHelper class ZipHelper
{ {

View File

@ -1,18 +1,18 @@
<?php <?php
namespace Box\Spout\Writer\Internal\XLSX; namespace Box\Spout\Writer\XLSX\Internal;
use Box\Spout\Writer\Exception\SheetNotFoundException; use Box\Spout\Writer\Exception\SheetNotFoundException;
use Box\Spout\Writer\Helper\XLSX\FileSystemHelper; use Box\Spout\Writer\XLSX\Helper\FileSystemHelper;
use Box\Spout\Writer\Helper\XLSX\SharedStringsHelper; use Box\Spout\Writer\XLSX\Helper\SharedStringsHelper;
use Box\Spout\Writer\Sheet; use Box\Spout\Writer\XLSX\Sheet;
/** /**
* Class Book * Class Book
* Represents a workbook within a XLSX file. * Represents a workbook within a XLSX file.
* It provides the functions to work with worksheets. * It provides the functions to work with worksheets.
* *
* @package Box\Spout\Writer\Internal\XLSX * @package Box\Spout\Writer\XLSX\Internal
*/ */
class Workbook class Workbook
{ {
@ -28,10 +28,10 @@ class Workbook
/** @var bool Whether new sheets should be automatically created when the max rows limit per sheet is reached */ /** @var bool Whether new sheets should be automatically created when the max rows limit per sheet is reached */
protected $shouldCreateNewSheetsAutomatically; protected $shouldCreateNewSheetsAutomatically;
/** @var \Box\Spout\Writer\Helper\XLSX\FileSystemHelper Helper to perform file system operations */ /** @var \Box\Spout\Writer\XLSX\Helper\FileSystemHelper Helper to perform file system operations */
protected $fileSystemHelper; protected $fileSystemHelper;
/** @var \Box\Spout\Writer\Helper\XLSX\SharedStringsHelper Helper to write shared strings */ /** @var \Box\Spout\Writer\XLSX\Helper\SharedStringsHelper Helper to write shared strings */
protected $sharedStringsHelper; protected $sharedStringsHelper;
/** @var Worksheet[] Array containing the workbook's sheets */ /** @var Worksheet[] Array containing the workbook's sheets */
@ -114,7 +114,7 @@ class Workbook
* Sets the given sheet as the current one. New data will be written to this sheet. * Sets the given sheet as the current one. New data will be written to this sheet.
* The writing will resume where it stopped (i.e. data won't be truncated). * The writing will resume where it stopped (i.e. data won't be truncated).
* *
* @param \Box\Spout\Writer\Sheet $sheet The "external" sheet to set as current * @param \Box\Spout\Writer\XLSX\Sheet $sheet The "external" sheet to set as current
* @return void * @return void
* @throws \Box\Spout\Writer\Exception\SheetNotFoundException If the given sheet does not exist in the workbook * @throws \Box\Spout\Writer\Exception\SheetNotFoundException If the given sheet does not exist in the workbook
*/ */
@ -140,7 +140,7 @@ class Workbook
/** /**
* Returns the worksheet associated to the given external sheet. * Returns the worksheet associated to the given external sheet.
* *
* @param \Box\Spout\Writer\Sheet $sheet * @param \Box\Spout\Writer\XLSX\Sheet $sheet
* @return Worksheet|null The worksheet associated to the given external sheet or null if not found. * @return Worksheet|null The worksheet associated to the given external sheet or null if not found.
*/ */
protected function getWorksheetFromExternalSheet($sheet) protected function getWorksheetFromExternalSheet($sheet)

View File

@ -1,17 +1,17 @@
<?php <?php
namespace Box\Spout\Writer\Internal\XLSX; namespace Box\Spout\Writer\XLSX\Internal;
use Box\Spout\Common\Exception\InvalidArgumentException; use Box\Spout\Common\Exception\InvalidArgumentException;
use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Exception\IOException;
use Box\Spout\Writer\Helper\XLSX\CellHelper; use Box\Spout\Writer\XLSX\Helper\CellHelper;
/** /**
* Class Worksheet * Class Worksheet
* Represents a worksheet within a XLSX file. The difference with the Sheet object is * Represents a worksheet within a XLSX file. The difference with the Sheet object is
* that this class provides an interface to write data * that this class provides an interface to write data
* *
* @package Box\Spout\Writer\Internal\XLSX * @package Box\Spout\Writer\XLSX\Internal
*/ */
class Worksheet class Worksheet
{ {
@ -20,13 +20,13 @@ class Worksheet
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
EOD; EOD;
/** @var \Box\Spout\Writer\Sheet The "external" sheet */ /** @var \Box\Spout\Writer\XLSX\Sheet The "external" sheet */
protected $externalSheet; protected $externalSheet;
/** @var string Path to the XML file that will contain the sheet data */ /** @var string Path to the XML file that will contain the sheet data */
protected $worksheetFilePath; protected $worksheetFilePath;
/** @var \Box\Spout\Writer\Helper\XLSX\SharedStringsHelper Helper to write shared strings */ /** @var \Box\Spout\Writer\XLSX\Helper\SharedStringsHelper Helper to write shared strings */
protected $sharedStringsHelper; protected $sharedStringsHelper;
/** @var bool Whether inline or shared strings should be used */ /** @var bool Whether inline or shared strings should be used */
@ -42,9 +42,9 @@ EOD;
protected $lastWrittenRowIndex = 0; protected $lastWrittenRowIndex = 0;
/** /**
* @param \Box\Spout\Writer\Sheet $externalSheet The associated "external" sheet * @param \Box\Spout\Writer\XLSX\Sheet $externalSheet The associated "external" sheet
* @param string $worksheetFilesFolder Temporary folder where the files to create the XLSX will be stored * @param string $worksheetFilesFolder Temporary folder where the files to create the XLSX will be stored
* @param \Box\Spout\Writer\Helper\XLSX\SharedStringsHelper $sharedStringsHelper Helper for shared strings * @param \Box\Spout\Writer\XLSX\Helper\SharedStringsHelper $sharedStringsHelper Helper for shared strings
* @param bool $shouldUseInlineStrings Whether inline or shared strings should be used * @param bool $shouldUseInlineStrings Whether inline or shared strings should be used
* @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing * @throws \Box\Spout\Common\Exception\IOException If the sheet data file cannot be opened for writing
*/ */
@ -76,7 +76,7 @@ EOD;
} }
/** /**
* @return \Box\Spout\Writer\Sheet The "external" sheet * @return \Box\Spout\Writer\XLSX\Sheet The "external" sheet
*/ */
public function getExternalSheet() public function getExternalSheet()
{ {

View File

@ -1,12 +1,12 @@
<?php <?php
namespace Box\Spout\Writer; namespace Box\Spout\Writer\XLSX;
/** /**
* Class Sheet * Class Sheet
* Represents a worksheet within a XLSX file * Represents a worksheet within a XLSX file
* *
* @package Box\Spout\Writer * @package Box\Spout\Writer\XLSX
*/ */
class Sheet class Sheet
{ {
@ -45,7 +45,7 @@ class Sheet
/** /**
* @param string $name Name of the sheet * @param string $name Name of the sheet
* @return \Box\Spout\Writer\Sheet * @return Sheet
*/ */
public function setName($name) public function setName($name)
{ {

View File

@ -1,17 +1,18 @@
<?php <?php
namespace Box\Spout\Writer; namespace Box\Spout\Writer\XLSX;
use Box\Spout\Writer\AbstractWriter;
use Box\Spout\Writer\Exception\WriterNotOpenedException; use Box\Spout\Writer\Exception\WriterNotOpenedException;
use Box\Spout\Writer\Internal\XLSX\Workbook; use Box\Spout\Writer\XLSX\Internal\Workbook;
/** /**
* Class XLSX * Class Writer
* This class provides base support to write data to XLSX files * This class provides base support to write data to XLSX files
* *
* @package Box\Spout\Writer * @package Box\Spout\Writer\XLSX
*/ */
class XLSX extends AbstractWriter class Writer extends AbstractWriter
{ {
/** @var string Content-Type value for the header */ /** @var string Content-Type value for the header */
protected static $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; protected static $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
@ -25,7 +26,7 @@ class XLSX extends AbstractWriter
/** @var bool Whether new sheets should be automatically created when the max rows limit per sheet is reached */ /** @var bool Whether new sheets should be automatically created when the max rows limit per sheet is reached */
protected $shouldCreateNewSheetsAutomatically = true; protected $shouldCreateNewSheetsAutomatically = true;
/** @var Internal\XLSX\Workbook The workbook for the XLSX file */ /** @var Internal\Workbook The workbook for the XLSX file */
protected $book; protected $book;
/** @var int */ /** @var int */
@ -33,7 +34,7 @@ class XLSX extends AbstractWriter
/** /**
* @param string $tempFolder Temporary folder where the files to create the XLSX will be stored * @param string $tempFolder Temporary folder where the files to create the XLSX will be stored
* @return XLSX * @return Writer
*/ */
public function setTempFolder($tempFolder) public function setTempFolder($tempFolder)
{ {
@ -45,7 +46,7 @@ class XLSX extends AbstractWriter
* Use inline string to be more memory efficient. If set to false, it will use shared strings. * Use inline string to be more memory efficient. If set to false, it will use shared strings.
* *
* @param bool $shouldUseInlineStrings Whether inline or shared strings should be used * @param bool $shouldUseInlineStrings Whether inline or shared strings should be used
* @return XLSX * @return Writer
*/ */
public function setShouldUseInlineStrings($shouldUseInlineStrings) public function setShouldUseInlineStrings($shouldUseInlineStrings)
{ {
@ -55,7 +56,7 @@ class XLSX extends AbstractWriter
/** /**
* @param bool $shouldCreateNewSheetsAutomatically Whether new sheets should be automatically created when the max rows limit per sheet is reached * @param bool $shouldCreateNewSheetsAutomatically Whether new sheets should be automatically created when the max rows limit per sheet is reached
* @return XLSX * @return Writer
*/ */
public function setShouldCreateNewSheetsAutomatically($shouldCreateNewSheetsAutomatically) public function setShouldCreateNewSheetsAutomatically($shouldCreateNewSheetsAutomatically)
{ {
@ -91,7 +92,7 @@ class XLSX extends AbstractWriter
$externalSheets = []; $externalSheets = [];
$worksheets = $this->book->getWorksheets(); $worksheets = $this->book->getWorksheets();
/** @var Internal\XLSX\Worksheet $worksheet */ /** @var Internal\Worksheet $worksheet */
foreach ($worksheets as $worksheet) { foreach ($worksheets as $worksheet) {
$externalSheets[] = $worksheet->getExternalSheet(); $externalSheets[] = $worksheet->getExternalSheet();
} }

View File

@ -1,16 +1,17 @@
<?php <?php
namespace Box\Spout\Writer; namespace Box\Spout\Writer\CSV;
use Box\Spout\Common\Type; use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource; use Box\Spout\TestUsingResource;
use Box\Spout\Writer\WriterFactory;
/** /**
* Class CSVTest * Class WriterTest
* *
* @package Box\Spout\Writer * @package Box\Spout\Writer\CSV
*/ */
class CSVTest extends \PHPUnit_Framework_TestCase class WriterTest extends \PHPUnit_Framework_TestCase
{ {
use TestUsingResource; use TestUsingResource;
@ -69,7 +70,7 @@ class CSVTest extends \PHPUnit_Framework_TestCase
]; ];
$writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_utf8_bom.csv'); $writtenContent = $this->writeToCsvFileAndReturnWrittenContent($allRows, 'csv_with_utf8_bom.csv');
$this->assertContains(CSV::UTF8_BOM, $writtenContent, 'The CSV file should contain a UTF-8 BOM'); $this->assertContains(Writer::UTF8_BOM, $writtenContent, 'The CSV file should contain a UTF-8 BOM');
} }
/** /**
@ -161,6 +162,6 @@ class CSVTest extends \PHPUnit_Framework_TestCase
private function trimWrittenContent($writtenContent) private function trimWrittenContent($writtenContent)
{ {
// remove line feeds and UTF-8 BOM // remove line feeds and UTF-8 BOM
return trim($writtenContent, PHP_EOL . CSV::UTF8_BOM); return trim($writtenContent, PHP_EOL . Writer::UTF8_BOM);
} }
} }

View File

@ -1,11 +1,11 @@
<?php <?php
namespace Box\Spout\Writer\Helper\XLSX; namespace Box\Spout\Writer\XLSX\Helper;
/** /**
* Class CellHelperTest * Class CellHelperTest
* *
* @package Box\Spout\Writer\Helper\XLSX * @package Box\Spout\Writer\XLSX\Helper
*/ */
class CellHelperTest extends \PHPUnit_Framework_TestCase class CellHelperTest extends \PHPUnit_Framework_TestCase
{ {

View File

@ -1,14 +1,15 @@
<?php <?php
namespace Box\Spout\Writer; namespace Box\Spout\Writer\XLSX;
use Box\Spout\Common\Type; use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource; use Box\Spout\TestUsingResource;
use Box\Spout\Writer\WriterFactory;
/** /**
* Class SheetTest * Class SheetTest
* *
* @package Box\Spout\Writer * @package Box\Spout\Writer\XLSX
*/ */
class SheetTest extends \PHPUnit_Framework_TestCase class SheetTest extends \PHPUnit_Framework_TestCase
{ {
@ -69,7 +70,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$this->createGeneratedFolderIfNeeded($fileName); $this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName); $resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX $writer */ /** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX); $writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($resourcePath); $writer->openToFile($resourcePath);

View File

@ -1,16 +1,17 @@
<?php <?php
namespace Box\Spout\Writer; namespace Box\Spout\Writer\XLSX;
use Box\Spout\Common\Type; use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource; use Box\Spout\TestUsingResource;
use Box\Spout\Writer\WriterFactory;
/** /**
* Class XLSXTest * Class XLSXTest
* *
* @package Box\Spout\Writer * @package Box\Spout\Writer
*/ */
class XLSXTest extends \PHPUnit_Framework_TestCase class WriterTest extends \PHPUnit_Framework_TestCase
{ {
use TestUsingResource; use TestUsingResource;
@ -230,7 +231,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
$this->createGeneratedFolderIfNeeded($fileName); $this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName); $resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX $writer */ /** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX); $writer = WriterFactory::create(Type::XLSX);
$writer->setShouldUseInlineStrings(true); $writer->setShouldUseInlineStrings(true);
@ -278,7 +279,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
]; ];
// set the maxRowsPerSheet limit to 2 // set the maxRowsPerSheet limit to 2
\ReflectionHelper::setStaticValue('\Box\Spout\Writer\Internal\XLSX\Workbook', 'maxRowsPerWorksheet', 2); \ReflectionHelper::setStaticValue('\Box\Spout\Writer\XLSX\Internal\Workbook', 'maxRowsPerWorksheet', 2);
$writer = $this->writeToXLSXFile($dataRows, $fileName, true, $shouldCreateSheetsAutomatically = true); $writer = $this->writeToXLSXFile($dataRows, $fileName, true, $shouldCreateSheetsAutomatically = true);
$this->assertEquals(2, count($writer->getSheets()), '2 sheets should have been created.'); $this->assertEquals(2, count($writer->getSheets()), '2 sheets should have been created.');
@ -302,7 +303,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
]; ];
// set the maxRowsPerSheet limit to 2 // set the maxRowsPerSheet limit to 2
\ReflectionHelper::setStaticValue('\Box\Spout\Writer\Internal\XLSX\Workbook', 'maxRowsPerWorksheet', 2); \ReflectionHelper::setStaticValue('\Box\Spout\Writer\XLSX\Internal\Workbook', 'maxRowsPerWorksheet', 2);
$writer = $this->writeToXLSXFile($dataRows, $fileName, true, $shouldCreateSheetsAutomatically = false); $writer = $this->writeToXLSXFile($dataRows, $fileName, true, $shouldCreateSheetsAutomatically = false);
$this->assertEquals(1, count($writer->getSheets()), 'Only 1 sheet should have been created.'); $this->assertEquals(1, count($writer->getSheets()), 'Only 1 sheet should have been created.');
@ -348,14 +349,14 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
* @param string $fileName * @param string $fileName
* @param bool $shouldUseInlineStrings * @param bool $shouldUseInlineStrings
* @param bool $shouldCreateSheetsAutomatically * @param bool $shouldCreateSheetsAutomatically
* @return XLSX * @return Writer
*/ */
private function writeToXLSXFile($allRows, $fileName, $shouldUseInlineStrings = true, $shouldCreateSheetsAutomatically = true) private function writeToXLSXFile($allRows, $fileName, $shouldUseInlineStrings = true, $shouldCreateSheetsAutomatically = true)
{ {
$this->createGeneratedFolderIfNeeded($fileName); $this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName); $resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX $writer */ /** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX); $writer = WriterFactory::create(Type::XLSX);
$writer->setShouldUseInlineStrings($shouldUseInlineStrings); $writer->setShouldUseInlineStrings($shouldUseInlineStrings);
$writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically); $writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically);
@ -373,14 +374,14 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
* @param string $fileName * @param string $fileName
* @param bool $shouldUseInlineStrings * @param bool $shouldUseInlineStrings
* @param bool $shouldCreateSheetsAutomatically * @param bool $shouldCreateSheetsAutomatically
* @return XLSX * @return Writer
*/ */
private function writeToMultipleSheetsInXLSXFile($allRows, $numSheets, $fileName, $shouldUseInlineStrings = true, $shouldCreateSheetsAutomatically = true) private function writeToMultipleSheetsInXLSXFile($allRows, $numSheets, $fileName, $shouldUseInlineStrings = true, $shouldCreateSheetsAutomatically = true)
{ {
$this->createGeneratedFolderIfNeeded($fileName); $this->createGeneratedFolderIfNeeded($fileName);
$resourcePath = $this->getGeneratedResourcePath($fileName); $resourcePath = $this->getGeneratedResourcePath($fileName);
/** @var \Box\Spout\Writer\XLSX $writer */ /** @var \Box\Spout\Writer\XLSX\Writer $writer */
$writer = WriterFactory::create(Type::XLSX); $writer = WriterFactory::create(Type::XLSX);
$writer->setShouldUseInlineStrings($shouldUseInlineStrings); $writer->setShouldUseInlineStrings($shouldUseInlineStrings);
$writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically); $writer->setShouldCreateNewSheetsAutomatically($shouldCreateSheetsAutomatically);