Refactor Configuration

This commit is contained in:
Romain Neutron
2012-02-22 18:05:35 +01:00
parent ecc8feb143
commit aa9d5171b0
12 changed files with 170 additions and 350 deletions

View File

@@ -61,37 +61,38 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
public function setUp()
{
$this->markTestSkipped('To rewrite');
parent::setUp();
$specNotInstalled = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
$specNotInstalled->expects($this->any())
->method('getConfigurationFile')
->will(
$this->throwException(new Exception)
->method('getConfigurationsFile')
->will(
$this->throwException(new Exception)
);
$specExperience = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationsFile')
);
$specExperience->expects($this->any())
->method('getConfigurationFile')
->will(
$this->returnValue(
new \SplFileObject(__DIR__ . '/confTestFiles/config.yml')
)
->method('getConfigurationsFile')
->will(
$this->returnValue(
new \SplFileObject(__DIR__ . '/confTestFiles/config.yml')
)
);
$handler = new Configuration\Handler($specNotInstalled, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($specNotInstalled);
$this->confNotInstalled = new PhraseaCore\Configuration($handler);
$handler = new Configuration\Handler($specExperience, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($specExperience);
$this->object = new PhraseaCore\Configuration($handler);
}
@@ -277,28 +278,28 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
$configuration->write($arrayToBeWritten, 0, true);
@@ -315,28 +316,28 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
);
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$arrayToBeWritten = array(
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
'hello' => 'world'
, 'key' => array(
'keyone' => 'valueone'
, 'keytwo' => 'valuetwo'
)
);
try
@@ -355,19 +356,19 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
@@ -381,19 +382,19 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
->method('getConfigurationPathName')
->will(
$this->returnValue("unknow_path")
);
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
@@ -457,30 +458,30 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
touch(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationPathName')
);
$file = new \SplFileObject(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
$stub->expects($this->any())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
->method('getConfigurationPathName')
->will(
$this->returnValue($file->getPathname())
);
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
$handler = new Configuration\Handler($stub);
$configuration = new PhraseaCore\Configuration($handler);
$newScope = array("prod" => array('key' => 'value', 'key2' => 'value2'));
$newScope = array("prod" => array('key' => 'value', 'key2' => 'value2'));
//append new conf
$configuration->write($newScope, FILE_APPEND);
try
{
$configuration->getConfiguration();//it is not loaded
$configuration->getConfiguration(); //it is not loaded
$this->fail("should raise an exception");
}
catch (\Exception $e)
@@ -495,23 +496,5 @@ class ConfigurationTest extends \PhraseanetPHPUnitAbstract
unlink(__DIR__ . "/confTestFiles/yamlWriteTest.yml");
}
public function testSetHandler()
{
$handler = new Configuration\Handler(new Configuration\Application(), new Configuration\Parser\Yaml());
$this->object->setConfigurationHandler($handler);
$this->assertEquals($handler, $this->object->getConfigurationHandler());
}
public function testGetHandler()
{
$stub = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
);
$handler = new Configuration\Handler($stub, new Configuration\Parser\Yaml());
$this->assertEquals($handler, $this->object->getConfigurationHandler());
}
}

View File

@@ -64,12 +64,6 @@ no_display_errors:
cache: array_cache
missing_phraseanet:
##phraseanet:
##servername: 'http://dev.phrasea.net/'
##maintenance: false
##debug: true
##display_errors: true
##database: main_connexion
template_engine: twig_debug
orm: doctrine_test
cache: array_cache

View File

@@ -114,14 +114,12 @@ class CoreTest extends PhraseanetPHPUnitAbstract
set_new_overload(array($this, 'newCallback'));
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
new \Alchemy\Phrasea\Core\Configuration\Application()
, new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
);
$specification = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
$class = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration'
, array('isInstalled')
, array($handler)
, array($specification)
, 'ConfMock'
);

View File

@@ -814,11 +814,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
*/
protected function resetTwig()
{
$handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
new \Alchemy\Phrasea\Core\Configuration\Application(),
new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml()
);
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler);
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$serviceName = $configuration->getTemplating();
$confService = $configuration->getService($serviceName);