Introduce an options manager for all writers (#423)
This will improve the management of options and simplify some methods' signatures. This commit will also help moving the code to a better state regarding Dependency Injection.
This commit is contained in:
1 parent
f9d8ad8be3
commit
a366d0d0af
22 files changed
+447
-113
No files matched your search
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Manager;
|
||||
|
||||
/**
|
||||
* Class OptionsManagerTest
|
||||
*
|
||||
* @package Box\Spout\Writer\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 OptionsManager
|
||||
{
|
||||
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