Cell value objects (#383)

* first stab at cell objects, #182
* removed comment parameter, streamlined cell detection, more tests #182
* shorter constant names, missing isFormula() #182
* first batch of changes #182
* documentation #182
This commit is contained in:
madflow authored and Adrien Loison committed 2017-05-01 12:09:24 +02:00
1 parent 4e6db6a8a1
commit 4acd9ad087
6 files changed
+312 -18

No files matched your search

+55
View File
@@ -5,6 +5,7 @@ namespace Box\Spout\Writer\XLSX;
use Box\Spout\Common\Exception\SpoutException;
use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Cell;
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Writer\XLSX\Internal\Worksheet;
@@ -507,6 +508,60 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $finfo->file($resourcePath));
}
/**
* @return void
*/
public function testWriterShouldAcceptCellObjects()
{
$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')],
];
$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false);
foreach ($dataRows as $dataRow) {
/** @var Cell $cell */
foreach ($dataRow as $cell) {
$this->assertSharedStringWasWritten($fileName, $cell->getValue());
}
}
}
/**
* @return void
*/
public function testWriteShouldAcceptCellObjectsWithDifferentValueTypes()
{
$fileName = 'test_writer_should_accept_cell_objects_with_types.xlsx';
$dataRowsShared = [
[new Cell('i am a string')],
];
$dataRowsInline = [
[new Cell(51465), new Cell(true), new Cell(51465.5)]
];
$dataRows = array_merge($dataRowsShared, $dataRowsInline);
$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false);
foreach ($dataRowsShared as $dataRow) {
/** @var Cell $cell */
foreach ($dataRow as $cell) {
$this->assertSharedStringWasWritten($fileName, (string)$cell->getValue());
}
}
foreach ($dataRowsInline as $dataRow) {
/** @var Cell $cell */
foreach ($dataRow as $cell) {
$this->assertInlineDataWasWrittenToSheet($fileName, 1, $cell->getValue());
}
}
}
/**
* @param array $allRows
* @param string $fileName