Refactor readers for better di (#457)
* Refactor readers to get a proper DI Similar to what was done with writers, readers also needed to be updated to match the new way of doing things. This commits promotes a better DI (factories, injection through constructors). * Escapers should not be singletons Instead, they should be proper object that can be injected where needed.
This commit is contained in:
1 parent
4d6437fa77
commit
b7e46740ce
66 files changed
+1095
-618
No files matched your search
+5
-3
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Common\Escaper;
|
||||
namespace Box\Spout\Common\Helper\Escaper;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
|
||||
/**
|
||||
* Class ODSTest
|
||||
*
|
||||
* @package Box\Spout\Common\Escaper
|
||||
* @package Box\Spout\Common\Helper\Escaper
|
||||
*/
|
||||
class ODSTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -34,7 +36,7 @@ class ODSTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEscape($stringToEscape, $expectedEscapedString)
|
||||
{
|
||||
$escaper = \Box\Spout\Common\Escaper\ODS::getInstance();
|
||||
$escaper = new Escaper\ODS();
|
||||
$escapedString = $escaper->escape($stringToEscape);
|
||||
|
||||
$this->assertEquals($expectedEscapedString, $escapedString, 'Incorrect escaped string');
|
||||
+6
-6
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Common\Escaper;
|
||||
namespace Box\Spout\Common\Helper\Escaper;
|
||||
|
||||
use Box\Spout\Common\Helper\Escaper;
|
||||
|
||||
/**
|
||||
* Class XLSXTest
|
||||
*
|
||||
* @package Box\Spout\Common\Escaper
|
||||
* @package Box\Spout\Common\Helper\Escaper
|
||||
*/
|
||||
class XLSXTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -38,8 +40,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEscape($stringToEscape, $expectedEscapedString)
|
||||
{
|
||||
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
||||
$escaper = \Box\Spout\Common\Escaper\XLSX::getInstance();
|
||||
$escaper = new Escaper\XLSX();
|
||||
$escapedString = $escaper->escape($stringToEscape);
|
||||
|
||||
$this->assertEquals($expectedEscapedString, $escapedString, 'Incorrect escaped string');
|
||||
@@ -74,8 +75,7 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testUnescape($stringToUnescape, $expectedUnescapedString)
|
||||
{
|
||||
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
|
||||
$escaper = \Box\Spout\Common\Escaper\XLSX::getInstance();
|
||||
$escaper = new Escaper\XLSX();
|
||||
$unescapedString = $escaper->unescape($stringToUnescape);
|
||||
|
||||
$this->assertEquals($expectedUnescapedString, $unescapedString, 'Incorrect escaped string');
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Common\Manager;
|
||||
|
||||
/**
|
||||
* Class OptionsManagerTest
|
||||
*
|
||||
* @package Box\Spout\Common\Manager
|
||||
*/
|
||||
class OptionsManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testOptionsManagerShouldReturnDefaultOptionsIfNothingSet()
|
||||
{
|
||||
$optionsManager = new FakeOptionsManager();
|
||||
$this->assertEquals('foo-val', $optionsManager->getOption('foo'));
|
||||
$this->assertEquals(false, $optionsManager->getOption('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testOptionsManagerShouldReturnUpdatedOptionValue()
|
||||
{
|
||||
$optionsManager = new FakeOptionsManager();
|
||||
$optionsManager->setOption('foo', 'new-val');
|
||||
$this->assertEquals('new-val', $optionsManager->getOption('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testOptionsManagerShouldReturnNullIfNoDefaultValueSet()
|
||||
{
|
||||
$optionsManager = new FakeOptionsManager();
|
||||
$this->assertNull($optionsManager->getOption('baz'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testOptionsManagerShouldReturnNullIfNoOptionNotSupported()
|
||||
{
|
||||
$optionsManager = new FakeOptionsManager();
|
||||
$optionsManager->setOption('not-supported', 'something');
|
||||
$this->assertNull($optionsManager->getOption('not-supported'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Convert this to anonymous class when PHP < 7 support is dropped
|
||||
class FakeOptionsManager extends OptionsManagerAbstract
|
||||
{
|
||||
protected function getSupportedOptions()
|
||||
{
|
||||
return [
|
||||
'foo',
|
||||
'bar',
|
||||
'baz',
|
||||
];
|
||||
}
|
||||
|
||||
protected function setDefaultOptions()
|
||||
{
|
||||
$this->setOption('foo', 'foo-val');
|
||||
$this->setOption('bar', false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user