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

@@ -1,6 +1,6 @@
<?php
namespace Box\Spout\Reader\Common\Entity;
namespace Box\Spout\Common\Entity;
class CellTest extends \PHPUnit\Framework\TestCase
{
@@ -1,11 +1,10 @@
<?php
namespace Box\Spout\Writer\Common\Entity;
namespace Box\Spout\Common\Entity;
use Box\Spout\Writer\Common\Entity\Style\Style;
use PHPUnit\Framework\TestCase;
use Box\Spout\Common\Entity\Style\Style;
class RowTest extends TestCase
class RowTest extends \PHPUnit\Framework\TestCase
{
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Style
@@ -1,11 +1,8 @@
<?php
namespace Box\Spout\Writer\Common\EntityStyle;
namespace Box\Spout\Common\Entity\Style;
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;
@@ -1,8 +1,8 @@
<?php
namespace Box\Spout\Writer\Common\Entity\Style;
namespace Box\Spout\Common\Entity\Style;
use Box\Spout\Writer\Exception\InvalidColorException;
use Box\Spout\Common\Exception\InvalidColorException;
/**
* Class ColorTest
@@ -1,90 +0,0 @@
<?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, $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())
->setCells([]);
$this->assertTrue(is_object($row));
}
}
@@ -2,8 +2,8 @@
namespace Box\Spout\Reader\Common\Manager;
use Box\Spout\Reader\Common\Entity\Cell;
use Box\Spout\Reader\Common\Entity\Row;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use Box\Spout\Reader\XLSX\Creator\ManagerFactory;
@@ -37,7 +37,7 @@ class RowManagerTest extends \PHPUnit_Framework_TestCase
{
$rowManager = $this->createRowManager();
$rowToFill = new Row([]);
$rowToFill = new Row([], null);
foreach ($rowCells as $cellIndex => $cell) {
$rowToFill->setCellAtIndex($cell, $cellIndex);
}
@@ -70,7 +70,7 @@ class RowManagerTest extends \PHPUnit_Framework_TestCase
public function testIsEmptyRow(array $cells, $expectedIsEmpty)
{
$rowManager = $this->createRowManager();
$row = new Row($cells);
$row = new Row($cells, null);
$this->assertEquals($expectedIsEmpty, $rowManager->isEmpty($row));
}
@@ -104,7 +104,7 @@ class CellValueFormatterTest extends \PHPUnit_Framework_TestCase
if ($expectedDateAsString === null) {
$this->fail('An exception should have been thrown');
} else {
$this->assertInstanceOf('DateTime', $result);
$this->assertInstanceOf(\DateTime::class, $result);
$this->assertSame($expectedDateAsString, $result->format('Y-m-d H:i:s'));
}
} catch (InvalidValueException $exception) {
+1 -1
View File
@@ -2,13 +2,13 @@
namespace Box\Spout\Writer\CSV;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Exception\InvalidArgumentException;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Exception\WriterNotOpenedException;
use Box\Spout\Writer\RowCreationHelper;
@@ -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());
}
}
@@ -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
+1 -1
View File
@@ -2,6 +2,7 @@
namespace Box\Spout\Writer\ODS;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Exception\InvalidArgumentException;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Exception\SpoutException;
@@ -9,7 +10,6 @@ use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Helper\ZipHelper;
use Box\Spout\Writer\Exception\WriterAlreadyOpenedException;
use Box\Spout\Writer\Exception\WriterNotOpenedException;
@@ -2,16 +2,16 @@
namespace Box\Spout\Writer\ODS;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Entity\Style\Border;
use Box\Spout\Common\Entity\Style\Color;
use Box\Spout\Common\Entity\Style\Style;
use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Exception\WriterNotOpenedException;
use Box\Spout\Writer\RowCreationHelper;
+2 -2
View File
@@ -2,9 +2,9 @@
namespace Box\Spout\Writer;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Style\Style;
/**
* Trait RowCreationHelper
@@ -2,9 +2,9 @@
namespace Box\Spout\Writer\XLSX\Manager\Style;
use Box\Spout\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Entity\Style\Color;
/**
* Class StyleRegistryTest
+1 -1
View File
@@ -2,13 +2,13 @@
namespace Box\Spout\Writer\XLSX;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Exception\InvalidArgumentException;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Exception\SpoutException;
use Box\Spout\Common\Type;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Exception\WriterAlreadyOpenedException;
use Box\Spout\Writer\Exception\WriterNotOpenedException;
use Box\Spout\Writer\RowCreationHelper;
@@ -2,17 +2,17 @@
namespace Box\Spout\Writer\XLSX;
use Box\Spout\Common\Entity\Cell;
use Box\Spout\Common\Entity\Row;
use Box\Spout\Common\Entity\Style\Border;
use Box\Spout\Common\Entity\Style\Color;
use Box\Spout\Common\Entity\Style\Style;
use Box\Spout\Common\Type;
use Box\Spout\Reader\Wrapper\XMLReader;
use Box\Spout\TestUsingResource;
use Box\Spout\Writer\Common\Creator\EntityFactory;
use Box\Spout\Writer\Common\Creator\Style\BorderBuilder;
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\Entity\Style\Border;
use Box\Spout\Writer\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
use Box\Spout\Writer\Exception\WriterNotOpenedException;
use Box\Spout\Writer\RowCreationHelper;
@@ -26,7 +26,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
use TestUsingResource;
use RowCreationHelper;
/** @var \Box\Spout\Writer\Common\Entity\Style\Style */
/** @var \Box\Spout\Common\Entity\Style\Style */
private $defaultStyle;
/**
@@ -531,7 +531,7 @@ class WriterWithStyleTest extends \PHPUnit_Framework_TestCase
/**
* @param Row[] $allRows
* @param string $fileName
* @param \Box\Spout\Writer\Common\Entity\Style\Style|null $defaultStyle
* @param \Box\Spout\Common\Entity\Style\Style|null $defaultStyle
* @return Writer
*/
private function writeToXLSXFileWithDefaultStyle($allRows, $fileName, $defaultStyle)