Merge Reader and Writer entities

Merged Cell/Row/Style entities
This commit is contained in:
Adrien Loison committed 2017-11-19 02:54:17 +01:00
1 parent 4d1d1c1e87
commit f5168114d0
66 files changed
+183 -576

No files matched your search

@@ -2,8 +2,8 @@
namespace Box\Spout\Writer\Common\Creator\Style;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Common\Entity\Style\Border;
use Box\Spout\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
/**
@@ -37,7 +37,7 @@ class StyleBuilderTest extends \PHPUnit_Framework_TestCase
$mergedStyle = $styleMerger->merge($currentStyle, $baseStyle);
$this->assertEquals(null, $currentStyle->getBorder(), 'Current style has no border');
$this->assertInstanceOf('Box\Spout\Writer\Common\Entity\Style\Border', $baseStyle->getBorder(), 'Base style has a border');
$this->assertInstanceOf('Box\Spout\Writer\Common\Entity\Style\Border', $mergedStyle->getBorder(), 'Merged style has a border');
$this->assertInstanceOf(Border::class, $baseStyle->getBorder(), 'Base style has a border');
$this->assertInstanceOf(Border::class, $mergedStyle->getBorder(), 'Merged style has a border');
}
}
@@ -1,68 +0,0 @@
<?php
namespace Box\Spout\Writer\Common\Entity;
use Box\Spout\Writer\Common\Entity\Style\Style;
use PHPUnit\Framework\TestCase;
class CellTest extends TestCase
{
/**
* @return void
*/
public function testValidInstance()
{
$this->assertInstanceOf(Cell::class, new Cell('cell'));
$this->assertInstanceOf(Cell::class, new Cell('cell-with-style', $this->createMock(Style::class)));
}
/**
* @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());
}
}
@@ -1,102 +0,0 @@
<?php
namespace Box\Spout\Writer\Common\Entity;
use Box\Spout\Writer\Common\Entity\Style\Style;
use PHPUnit\Framework\TestCase;
class RowTest extends 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 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->assertTrue(is_object($row));
}
}
@@ -1,127 +0,0 @@
<?php
namespace Box\Spout\Writer\Common\EntityStyle;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\BorderPart;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Exception\Border\InvalidNameException;
use Box\Spout\Writer\Exception\Border\InvalidStyleException;
use Box\Spout\Writer\Exception\Border\InvalidWidthException;
/**
* Class BorderTest
*/
class BorderTest extends \PHPUnit_Framework_TestCase
{
/**
* @return void
*/
public function testValidInstance()
{
$noConstructorParams = new Border();
$withConstructorParams = new Border([
new BorderPart(Border::LEFT),
]);
}
/**
* @return void
*/
public function testInvalidBorderPart()
{
$this->expectException(InvalidNameException::class);
new BorderPart('invalid');
}
/**
* @return void
*/
public function testInvalidBorderPartStyle()
{
$this->expectException(InvalidStyleException::class);
new BorderPart(Border::LEFT, Color::BLACK, Border::WIDTH_THIN, 'invalid');
}
/**
* @return void
*/
public function testInvalidBorderPartWidth()
{
$this->expectException(InvalidWidthException::class);
new BorderPart(Border::LEFT, Color::BLACK, 'invalid', Border::STYLE_DASHED);
}
/**
* @return void
*/
public function testNotMoreThanFourPartsPossible()
{
$border = new Border();
$border
->addPart(new BorderPart(Border::LEFT))
->addPart(new BorderPart(Border::RIGHT))
->addPart(new BorderPart(Border::TOP))
->addPart(new BorderPart(Border::BOTTOM))
->addPart(new BorderPart(Border::LEFT));
$this->assertEquals(4, count($border->getParts()), 'There should never be more than 4 border parts');
}
/**
* @return void
*/
public function testSetParts()
{
$border = new Border();
$border->setParts([
new BorderPart(Border::LEFT),
]);
$this->assertEquals(1, count($border->getParts()), 'It should be possible to set the border parts');
}
/**
* @return void
*/
public function testBorderBuilderFluent()
{
$border = (new BorderBuilder())
->setBorderBottom()
->setBorderTop()
->setBorderLeft()
->setBorderRight()
->build();
$this->assertEquals(4, count($border->getParts()), 'The border builder exposes a fluent interface');
}
/**
* :D :S
* @return void
*/
public function testAnyCombinationOfAllowedBorderPartsParams()
{
$color = Color::BLACK;
foreach (BorderPart::getAllowedNames() as $allowedName) {
foreach (BorderPart::getAllowedStyles() as $allowedStyle) {
foreach (BorderPart::getAllowedWidths() as $allowedWidth) {
$borderPart = new BorderPart($allowedName, $color, $allowedWidth, $allowedStyle);
$border = new Border();
$border->addPart($borderPart);
$this->assertEquals(1, count($border->getParts()));
/** @var $part BorderPart */
$part = $border->getParts()[$allowedName];
$this->assertEquals($allowedStyle, $part->getStyle());
$this->assertEquals($allowedWidth, $part->getWidth());
$this->assertEquals($color, $part->getColor());
}
}
}
}
}
@@ -1,93 +0,0 @@
<?php
namespace Box\Spout\Writer\Common\Entity\Style;
use Box\Spout\Writer\Exception\InvalidColorException;
/**
* Class ColorTest
*/
class ColorTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestRGB()
{
return [
[0, 0, 0, Color::BLACK],
[255, 255, 255, Color::WHITE],
[255, 0, 0, Color::RED],
[192, 0, 0, Color::DARK_RED],
[255, 192, 0, Color::ORANGE],
[255, 255, 0, Color::YELLOW],
[146, 208, 64, Color::LIGHT_GREEN],
[0, 176, 80, Color::GREEN],
[0, 176, 224, Color::LIGHT_BLUE],
[0, 112, 192, Color::BLUE],
[0, 32, 96, Color::DARK_BLUE],
[112, 48, 160, Color::PURPLE],
[0, 0, 0, '000000'],
[255, 255, 255, 'FFFFFF'],
[255, 0, 0, 'FF0000'],
[0, 128, 0, '008000'],
[0, 255, 0, '00FF00'],
[0, 0, 255, '0000FF'],
[128, 22, 43, '80162B'],
];
}
/**
* @dataProvider dataProviderForTestRGB
*
* @param int $red
* @param int $green
* @param int $blue
* @param string $expectedColor
* @return void
*/
public function testRGB($red, $green, $blue, $expectedColor)
{
$color = Color::rgb($red, $green, $blue);
$this->assertEquals($expectedColor, $color);
}
/**
* @return array
*/
public function dataProviderForTestRGBAInvalidColorComponents()
{
return [
[-1, 0, 0],
[0, -1, 0],
[0, 0, -1],
[999, 0, 0],
[0, 999, 0],
[0, 0, 999],
[null, 0, 0],
[0, null, 0],
[0, 0, null],
['1', 0, 0],
[0, '1', 0],
[0, 0, '1'],
[true, 0, 0],
[0, true, 0],
[0, 0, true],
];
}
/**
* @dataProvider dataProviderForTestRGBAInvalidColorComponents
*
* @param int $red
* @param int $green
* @param int $blue
* @return void
*/
public function testRGBInvalidColorComponents($red, $green, $blue)
{
$this->expectException(InvalidColorException::class);
Color::rgb($red, $green, $blue);
}
}
@@ -2,8 +2,8 @@
namespace Spout\Writer\Common\Manager;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Manager\CellManager;
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
use PHPUnit\Framework\TestCase;
@@ -2,8 +2,8 @@
namespace Spout\Writer\Common\Manager;
use Box\Spout\Writer\Common\Entity\Cell;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Writer\Common\Manager\RowManager;
use PHPUnit\Framework\TestCase;
@@ -2,8 +2,8 @@
namespace Box\Spout\Writer\Common\Manager\Style;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Cell;
/**
* Class StyleManagerTest
@@ -2,9 +2,9 @@
namespace Box\Spout\Writer\Common\Manager\Style;
use Box\Spout\Common\Entity\Style\Color;
use Box\Spout\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Entity\Style\Style;
/**
* Class StyleMergerTest
@@ -2,8 +2,8 @@
namespace Box\Spout\Writer\Common\Manager\Style;
use Box\Spout\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Style\Style;
/**
* Class StyleRegistryTest