Make ODS reader return Row object

This commit is contained in:
Adrien Loison committed 2017-11-19 01:36:18 +01:00
1 parent 68a96367a8
commit 102e17159c
16 files changed
+301 -67

No files matched your search

@@ -0,0 +1,41 @@
<?php
namespace Box\Spout\Reader\ODS\Manager;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
/**
* Class RowManagerTest
*/
class RowManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestIsEmptyRow()
{
return [
// cells, expected isEmpty
[[], true],
[[new Cell('')], true],
[[new Cell(''), new Cell('')], true],
[[new Cell(''), new Cell(''), new Cell('Okay')], false],
];
}
/**
* @dataProvider dataProviderForTestIsEmptyRow
*
* @param array $cells
* @param bool $expectedIsEmpty
* @return void
*/
public function testIsEmptyRow(array $cells, $expectedIsEmpty)
{
$rowManager = new RowManager();
$row = new Row($cells);
$this->assertEquals($expectedIsEmpty, $rowManager->isEmpty($row));
}
}
+4 -3
View File
@@ -377,6 +377,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
$allRows = [];
$resourcePath = $this->getResourcePath('two_sheets_with_strings.ods');
/** @var Reader $reader */
$reader = EntityFactory::createReader(Type::ODS);
$reader->open($resourcePath);
@@ -387,7 +388,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
// this loop should only add the first row of each sheet
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
break;
}
}
@@ -395,7 +396,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
// this loop should only add the first row of the first sheet
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
break;
}
@@ -536,7 +537,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
foreach ($reader->getSheetIterator() as $sheetIndex => $sheet) {
foreach ($sheet->getRowIterator() as $rowIndex => $row) {
$allRows[] = $row;
$allRows[] = $row->toArray();
}
}
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX\Helper;
use Box\Spout\Common\Helper\Escaper;
use Box\Spout\Reader\Exception\InvalidValueException;
use Box\Spout\Reader\XLSX\Manager\StyleManager;
/**
@@ -96,13 +97,18 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true));
$formatter = new CellValueFormatter(null, $styleManagerMock, false, $shouldUse1904Dates, new Escaper\XLSX());
$result = $formatter->extractAndFormatNodeValue($nodeMock);
if ($expectedDateAsString === null) {
$this->assertNull($result);
} else {
$this->assertInstanceOf('DateTime', $result);
$this->assertSame($expectedDateAsString, $result->format('Y-m-d H:i:s'));
try {
$result = $formatter->extractAndFormatNodeValue($nodeMock);
if ($expectedDateAsString === null) {
$this->fail('An exception should have been thrown');
} else {
$this->assertInstanceOf('DateTime', $result);
$this->assertSame($expectedDateAsString, $result->format('Y-m-d H:i:s'));
}
} catch (InvalidValueException $exception) {
// do nothing
}
}
@@ -9,7 +9,7 @@ use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
/**
* Class SharedStringsManagerTest
* Class RowManagerTest
*/
class RowManagerTest extends \PHPUnit_Framework_TestCase
{