spout/tests/Spout/Common/Entity/RowTest.php
Adrien Loison 16a2f91a22 Cell indexes not being respected when rendering row
Fixes #682
When calling `Row::setCellIndex`, it's possible to create a Row with holes.
Instead of iterating over existing cells of a Row, we should instead use the cell indexes (from 0 to max cell index).
2019-09-28 14:02:23 +00:00

128 lines
2.8 KiB
PHP

<?php
namespace Box\Spout\Common\Entity;
use Box\Spout\Common\Entity\Style\Style;
class RowTest extends \PHPUnit\Framework\TestCase
{
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Style
*/
private function getStyleMock()
{
return $this->createMock(Style::class);
}
/**
* @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, $row->getNumCells());
}
/**
* @return void
*/
public function testSetCellsResets()
{
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, $row->getNumCells());
$row->setCells([$this->getCellMock()]);
$this->assertEquals(1, $row->getNumCells());
}
/**
* @return void
*/
public function testGetCells()
{
$row = new Row([], null);
$this->assertEquals(0, $row->getNumCells());
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, $row->getNumCells());
}
/**
* @return void
*/
public function testGetCellAtIndex()
{
$row = new Row([], null);
$cellMock = $this->getCellMock();
$row->setCellAtIndex($cellMock, 3);
$this->assertEquals($cellMock, $row->getCellAtIndex(3));
$this->assertNull($row->getCellAtIndex(10));
}
/**
* @return void
*/
public function testSetCellAtIndex()
{
$row = new Row([], null);
$cellMock = $this->getCellMock();
$row->setCellAtIndex($cellMock, 1);
$this->assertEquals(2, $row->getNumCells());
$this->assertNull($row->getCellAtIndex(0));
}
/**
* @return void
*/
public function testAddCell()
{
$row = new Row([], null);
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
$this->assertEquals(2, $row->getNumCells());
$row->addCell($this->getCellMock());
$this->assertEquals(3, $row->getNumCells());
}
/**
* @return void
*/
public function testFluentInterface()
{
$row = new Row([], null);
$row
->addCell($this->getCellMock())
->setStyle($this->getStyleMock())
->setCells([]);
$this->assertInternalType('object', $row);
}
}