Skip to content

Commit

Permalink
Better support for errored cells
Browse files Browse the repository at this point in the history
  • Loading branch information
adrilo committed Jun 3, 2018
1 parent 1b64a06 commit f7c483a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Spout/Common/Entity/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function setValue($value)
*/
public function getValue()
{
return $this->value;
return !$this->isError() ? $this->value : null;
}

/**
Expand Down Expand Up @@ -203,6 +203,6 @@ public function isError()
*/
public function __toString()
{
return (string) $this->value;
return (string) $this->getValue();
}
}
2 changes: 1 addition & 1 deletion src/Spout/Common/Entity/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function setStyle($style)
public function toArray()
{
return array_map(function (Cell $cell) {
return !$cell->isError() ? $cell->getValue() : null;
return $cell->getValue();
}, $this->cells);
}
}
14 changes: 13 additions & 1 deletion tests/Spout/Common/Entity/CellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Box\Spout\Common\Entity;

class CellTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\TestCase;

class CellTest extends TestCase
{
/**
* @return void
Expand Down Expand Up @@ -70,4 +72,14 @@ public function testCellTypeError()
{
$this->assertTrue((new Cell([]))->isError());
}

/**
* @return void
*/
public function testErroredCellValueShouldBeNull()
{
$cell = new Cell([]);
$this->assertTrue($cell->isError());
$this->assertNull($cell->getValue());
}
}

0 comments on commit f7c483a

Please sign in to comment.