Better support for errored cells
This commit is contained in:
parent
1b64a06fbe
commit
f7c483adbd
@ -88,7 +88,7 @@ class Cell
|
|||||||
*/
|
*/
|
||||||
public function getValue()
|
public function getValue()
|
||||||
{
|
{
|
||||||
return $this->value;
|
return !$this->isError() ? $this->value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,6 +203,6 @@ class Cell
|
|||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return (string) $this->value;
|
return (string) $this->getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class Row
|
|||||||
public function toArray()
|
public function toArray()
|
||||||
{
|
{
|
||||||
return array_map(function (Cell $cell) {
|
return array_map(function (Cell $cell) {
|
||||||
return !$cell->isError() ? $cell->getValue() : null;
|
return $cell->getValue();
|
||||||
}, $this->cells);
|
}, $this->cells);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Box\Spout\Common\Entity;
|
namespace Box\Spout\Common\Entity;
|
||||||
|
|
||||||
class CellTest extends \PHPUnit\Framework\TestCase
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class CellTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
@ -70,4 +72,14 @@ class CellTest extends \PHPUnit\Framework\TestCase
|
|||||||
{
|
{
|
||||||
$this->assertTrue((new Cell([]))->isError());
|
$this->assertTrue((new Cell([]))->isError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testErroredCellValueShouldBeNull()
|
||||||
|
{
|
||||||
|
$cell = new Cell([]);
|
||||||
|
$this->assertTrue($cell->isError());
|
||||||
|
$this->assertNull($cell->getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user