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:
Adrien Loison authored and GitHub committed 2017-08-27 00:01:17 +02:00
1 parent 4d6437fa77
commit b7e46740ce
66 files changed
+1095 -618

No files matched your search

@@ -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);
}
}