StyleMerger and RowManager changes
Move DI of StyleMerger to get rid of business logic in the entities Cell and Row Simplify RowManager
This commit is contained in:
1 parent
111f82d35f
commit
ddfa40e8b3
10 files changed
+67
-166
No files matched your search
@@ -3,7 +3,6 @@
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Writer\Common\Entity\Style\Style;
|
||||
use Box\Spout\Writer\Common\Manager\RowManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RowTest extends TestCase
|
||||
@@ -24,23 +23,12 @@ class RowTest extends TestCase
|
||||
return $this->createMock(Cell::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject|RowManager
|
||||
*/
|
||||
private function getRowManagerMock()
|
||||
{
|
||||
return $this->createMock(RowManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testValidInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Row::class,
|
||||
new Row([], null, $this->getRowManagerMock())
|
||||
);
|
||||
$this->assertInstanceOf(Row::class, new Row([], null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +36,7 @@ class RowTest extends TestCase
|
||||
*/
|
||||
public function testSetCells()
|
||||
{
|
||||
$row = new Row([], null, $this->getRowManagerMock());
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
@@ -59,7 +47,7 @@ class RowTest extends TestCase
|
||||
*/
|
||||
public function testSetCellsResets()
|
||||
{
|
||||
$row = new Row([], null, $this->getRowManagerMock());
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
@@ -74,7 +62,7 @@ class RowTest extends TestCase
|
||||
*/
|
||||
public function testGetCells()
|
||||
{
|
||||
$row = new Row([], null, $this->getRowManagerMock());
|
||||
$row = new Row([], null);
|
||||
|
||||
$this->assertEquals(0, count($row->getCells()));
|
||||
|
||||
@@ -88,7 +76,7 @@ class RowTest extends TestCase
|
||||
*/
|
||||
public function testAddCell()
|
||||
{
|
||||
$row = new Row([], null, $this->getRowManagerMock());
|
||||
$row = new Row([], null);
|
||||
$row->setCells([$this->getCellMock(), $this->getCellMock()]);
|
||||
|
||||
$this->assertEquals(2, count($row->getCells()));
|
||||
@@ -103,7 +91,7 @@ class RowTest extends TestCase
|
||||
*/
|
||||
public function testFluentInterface()
|
||||
{
|
||||
$row = new Row([], null, $this->getRowManagerMock());
|
||||
$row = new Row([], null);
|
||||
$row
|
||||
->addCell($this->getCellMock())
|
||||
->setStyle($this->getStyleMock())
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Spout\Writer\Common\Manager;
|
||||
|
||||
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
|
||||
use Box\Spout\Writer\Common\Entity\Cell;
|
||||
use Box\Spout\Writer\Common\Entity\Row;
|
||||
use Box\Spout\Writer\Common\Manager\RowManager;
|
||||
@@ -11,51 +10,6 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RowManagerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testApplyStyle()
|
||||
{
|
||||
$rowManager = new RowManager(new StyleMerger());
|
||||
$row = new Row([new Cell('test')], null, $rowManager);
|
||||
|
||||
$this->assertFalse($row->getStyle()->isFontBold());
|
||||
|
||||
$style = (new StyleBuilder())->setFontBold()->build();
|
||||
$rowManager->applyStyle($row, $style);
|
||||
|
||||
$this->assertTrue($row->getStyle()->isFontBold());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderForTestHasCells()
|
||||
{
|
||||
return [
|
||||
// cells, expected hasCells
|
||||
[[], false],
|
||||
[[new Cell('')], true],
|
||||
[[new Cell(null)], true],
|
||||
[[new Cell('test')], true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderForTestHasCells
|
||||
*
|
||||
* @param array $cells
|
||||
* @param bool $expectedHasCells
|
||||
* @return void
|
||||
*/
|
||||
public function testHasCells(array $cells, $expectedHasCells)
|
||||
{
|
||||
$rowManager = new RowManager(new StyleMerger());
|
||||
|
||||
$row = new Row($cells, null, $rowManager);
|
||||
$this->assertEquals($expectedHasCells, $rowManager->hasCells($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user