Empty rows do not need to be written for XLSX files (#336)

This commit is contained in:
Adrien Loison authored and GitHub committed 2016-10-17 11:40:52 -07:00
1 parent 2fafb63115
commit 179ab483d6
4 files changed
+83 -5

No files matched your search

@@ -35,6 +35,23 @@ class CellHelperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedCellIndex, CellHelper::getCellIndexFromColumnIndex($columnIndex));
}
/**
* @return array
*/
public function testIsEmpty()
{
$this->assertTrue(CellHelper::isEmpty(null));
$this->assertTrue(CellHelper::isEmpty(""));
$this->assertFalse(CellHelper::isEmpty("string"));
$this->assertFalse(CellHelper::isEmpty(0));
$this->assertFalse(CellHelper::isEmpty(1));
$this->assertFalse(CellHelper::isEmpty(true));
$this->assertFalse(CellHelper::isEmpty(false));
$this->assertFalse(CellHelper::isEmpty(["string"]));
$this->assertFalse(CellHelper::isEmpty(new \stdClass()));
}
/**
* @return array
*/
+25 -2
View File
@@ -108,7 +108,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
/**
* @return void
*/
public function testAddRowShouldCleanupAllFilesIfExceptionIsThrown2()
public function testAddRowShouldCleanupAllFilesIfExceptionIsThrown()
{
$fileName = 'test_add_row_should_cleanup_all_files_if_exception_thrown.xlsx';
$dataRows = [
@@ -276,7 +276,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
['foo' => 'xlsx--11', 'bar' => 'xlsx--12'],
];
$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = true);
$this->writeToXLSXFile($dataRows, $fileName);
foreach ($dataRows as $dataRow) {
foreach ($dataRow as $cellValue) {
@@ -285,6 +285,29 @@ class WriterTest extends \PHPUnit_Framework_TestCase
}
}
/**
* @return void
*/
public function testAddRowShouldNotWriteEmptyRows()
{
$fileName = 'test_add_row_should_not_write_empty_rows.xlsx';
$dataRows = [
[''],
['xlsx--21', 'xlsx--22'],
[''],
[''],
['xlsx--51', 'xlsx--52'],
];
$this->writeToXLSXFile($dataRows, $fileName);
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 'row r="2"');
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 'row r="5"');
$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, 'row r="1"');
$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, 'row r="3"');
$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, 'row r="4"');
}
/**
* @return void
*/