Make CSV reader return Row objects
This commit is contained in:
1 parent
139f7fdfb3
commit
a665b974fa
37 files changed
+664
-214
No files matched your search
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\Common\Entity;
|
||||
|
||||
class CellTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testValidInstance()
|
||||
{
|
||||
$this->assertInstanceOf(Cell::class, new Cell('cell'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeNumeric()
|
||||
{
|
||||
$this->assertTrue((new Cell(0))->isNumeric());
|
||||
$this->assertTrue((new Cell(1))->isNumeric());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeString()
|
||||
{
|
||||
$this->assertTrue((new Cell('String!'))->isString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeEmptyString()
|
||||
{
|
||||
$this->assertTrue((new Cell(''))->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeEmptyNull()
|
||||
{
|
||||
$this->assertTrue((new Cell(null))->isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeBool()
|
||||
{
|
||||
$this->assertTrue((new Cell(true))->isBoolean());
|
||||
$this->assertTrue((new Cell(false))->isBoolean());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCellTypeError()
|
||||
{
|
||||
$this->assertTrue((new Cell([]))->isError());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Reader\Common\Entity;
|
||||
|
||||
class RowTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|Cell
|
||||
*/
|
||||
private function getCellMock()
|
||||
{
|
||||
return $this->createMock(Cell::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testValidInstance()
|
||||
{
|
||||
$this->assertInstanceOf(Row::class, new Row([], null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetCells()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetCellsResets()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
|
||||
$row->setCells([$this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(1, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetCells()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
|
||||
$this->assertEquals(0, count($row->getCells()));
|
||||
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddCell()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
|
||||
$row->addCell($this->getCellMock());
|
||||
|
||||
$this->assertEquals(3, count($row->getCells()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testFluentInterface()
|
||||
{
|
||||
$row = new Row([], null);
|
||||
$row
|
||||
->addCell($this->getCellMock())
|
||||
->setCells([]);
|
||||
|
||||
$this->assertTrue(is_object($row));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user