refactor configuration tests

This commit is contained in:
Nicolas Le Goff
2012-01-24 15:58:18 +01:00
parent 24c991efcf
commit b6b9e4a889
8 changed files with 273 additions and 662 deletions

View File

@@ -23,154 +23,147 @@ use Alchemy\Phrasea\Core\Configuration;
class ConfigurationTest extends \PhraseanetPHPUnitAbstract class ConfigurationTest extends \PhraseanetPHPUnitAbstract
{ {
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confProd;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confDev;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confTest;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confNotInstalled;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $confExperience;
/**
*
* @var \Alchemy\Phrasea\Core\Configuration
*/
protected $object;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
}
public function testInitialization() $specNotInstalled = $this->getMock(
{
$spec = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application' '\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile') , array('getConfigurationFile')
); );
$fileName = __DIR__ . '/confTestFiles/good.yml'; $specNotInstalled->expects($this->any())
$spec->expects($this->any())
->method('getConfigurationFile') ->method('getConfigurationFile')
->will( ->will(
$this->returnValue( $this->throwException(new Exception)
new \SplFileObject($fileName)
)
); );
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); $specExperience = $this->getMock(
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$this->assertEquals('prod', $configuration->getEnvironnement());
$this->assertTrue($configuration->isInstalled());
$this->assertInstanceOf(
'\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag'
, $configuration->getConfiguration()
);
$this->assertFalse($configuration->isDebug());
$this->assertFalse($configuration->isDisplayingErrors());
$this->assertFalse($configuration->isMaintained());
$this->assertTrue(is_array($configuration->getPhraseanet()->all()));
}
public function testInstalled()
{
$spec = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application' '\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile') , array('getConfigurationFile')
); );
$spec->expects($this->any()) $specExperience->expects($this->any())
->method('getConfigurationFile')
->will($this->throwException(new \Exception()));
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$this->assertFalse($configuration->isInstalled());
try
{
$configuration->getPhraseanet();
$this->fail("should raise an exception because application is not yet installed");
}
catch (\Exception $e)
{
}
}
public function testGetAvailableLogger()
{
$spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application');
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$availableLogger = $configuration->getAvailableDoctrineLogger();
$this->assertTrue(is_array($availableLogger));
$this->assertContains('monolog', $availableLogger);
$this->assertContains('echo', $availableLogger);
}
public function testGetHandler()
{
$spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application');
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration\Handler', $configuration->getConfigurationHandler());
}
public function testSetHandler()
{
$spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application');
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$configuration = new PhraseaCore\Configuration($handler);
$configuration->setEnvironnement('prod');
$spec2 = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application');
$spec2->expects($this->any())
->method('getConfigurationFile') ->method('getConfigurationFile')
->will( ->will(
$this->returnValue( $this->returnValue(
'test' new \SplFileObject(__DIR__ . '/confTestFiles/config.yml')
) )
); );
$newHandler = new Configuration\Handler($spec2, new Configuration\Parser\Yaml());
$configuration->setConfigurationHandler($newHandler); $handler = new Configuration\Handler($specNotInstalled, new Configuration\Parser\Yaml());
$this->confNotInstalled = new PhraseaCore\Configuration($handler);
$this->assertEquals('test', $configuration->getConfigurationHandler()->getSpecification()->getConfigurationFile());
$handler = new Configuration\Handler($specExperience, new Configuration\Parser\Yaml());
$this->object = new PhraseaCore\Configuration($handler);
} }
// public function testBadDoctrineLogger() public function testGetEnvironment()
{
$this->assertEquals("dev", $this->object->getEnvironnement());
$this->assertEquals(null, $this->confNotInstalled->getEnvironnement());
}
public function testSetEnvironment()
{
$this->object->setEnvironnement("ok");
$this->assertEquals("ok", $this->object->getEnvironnement());
$this->confNotInstalled->setEnvironnement("ok");
$this->assertEquals("ok", $this->confNotInstalled->getEnvironnement());
}
public function testIsDebug()
{
$this->object->setEnvironnement("test");
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("dev");
$this->assertTrue($this->object->isDebug());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDebug());
$this->object->setEnvironnement("no_debug");
$this->assertFalse($this->object->isDebug());
}
public function testIsMaintened()
{
$this->object->setEnvironnement("test");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("dev");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isMaintained());
$this->object->setEnvironnement("no_maintenance");
$this->assertFalse($this->object->isMaintained());
}
public function testIsDisplayinErrors()
{
$this->object->setEnvironnement("test");
$this->assertFalse($this->object->isDisplayingErrors());
$this->object->setEnvironnement("dev");
$this->assertFalse($this->object->isDisplayingErrors());
$this->object->setEnvironnement("prod");
$this->assertFalse($this->object->isDisplayingErrors());
$this->object->setEnvironnement("no_display_errors");
$this->assertFalse($this->object->isDisplayingErrors());
}
// public function testgetPhraseanet()
// { // {
// $spec = $this->getMock( // $this->object->setEnvironnement("test");
// '\Alchemy\Phrasea\Core\Configuration\Application' // $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
// , array('getConfigurationFile') // $this->object->setEnvironnement("dev");
// ); // $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
// // $this->object->setEnvironnement("prod");
// $fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml'; // $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
// // $this->object->setEnvironnement("missing_phraseanet");
// $spec->expects($this->any())
// ->method('getConfigurationFile')
// ->will(
// $this->returnValue(
// new \SplFileObject($fileName)
// )
// );
//
// $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
//
// $configuration = new PhraseaCore\Configuration($handler);
// $configuration->setEnvironnement('prod');
//
// try // try
// { // {
// $configuration->getDoctrine(); // $this->object->getPhraseanet();
// $this->fail('An exception should be raised'); // $this->fail("should raise an exeception");
// } // }
// catch(Exception $e) // catch (\Exception $e)
// { // {
// //
// } // }
// } // }
} }

View File

@@ -1,112 +0,0 @@
environment : dev
dev:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
output: json
type: monolog
handler: bad_logger
filename: doctrine-query.log
max_day: 2
monolog:
output: json
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
prod:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: false
display_errors: false
database:
host: localhost
port: 3306
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: apc
result: apc
metadata: apc
log:
output: json
enable: true
type: monolog
handler: bad_logger
filename: sql-query.log
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
test:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
monolog:
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10

View File

@@ -1,112 +1,75 @@
environment : dev environment: dev
dev:
dev: phraseanet:
phraseanet: servername: 'http://dev.phrasea.net/'
servername: http://dev.phrasea.net/ maintenance: false
maintenance: false debug: true
debug: true display_errors: true
display_errors: true database: main_connexion
database: template_engine: twig_debug
host: localhost orm: doctrine_dev
port: 3306 cache: array_cache
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
output: json
type: monolog
handler: rotate
filename: doctrine-query.log
max_day: 2
monolog:
output: json
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
prod: prod:
phraseanet: phraseanet:
servername: http://dev.phrasea.net/ servername: 'http://dev.phrasea.net/'
maintenance: false maintenance: false
debug: false debug: false
display_errors: false display_errors: false
database: database: main_connexion
host: localhost template_engine: twig
port: 3306 orm: doctrine_prod
dbname: ab_trunk cache: apc_cache
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: apc
result: apc
metadata: apc
log:
output: json
enable: true
type: monolog
handler: rotate
filename: sql-query.log
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
test: test:
phraseanet: phraseanet:
servername: http://dev.phrasea.net/ servername: 'http://dev.phrasea.net/'
maintenance: false maintenance: false
debug: true debug: true
display_errors: true display_errors: true
database: database: main_connexion
host: localhost template_engine: twig_debug
port: 3306 orm: doctrine_test
dbname: ab_trunk cache: array_cache
user: test
password: test
doctrine: no_debug:
dbal: phraseanet:
driver: pdo_sqlite servername: 'http://dev.phrasea.net/'
path: unpath maintenance: false
charset: UTF8 ##debug: true
orm: display_errors: true
cache: database: main_connexion
query: array template_engine: twig_debug
result: array orm: doctrine_test
metadata: array cache: array_cache
log:
enable: false no_maintenance:
monolog: phraseanet:
handlers: servername: 'http://dev.phrasea.net/'
main: ##maintenance: false
type: stream debug: true
rotate: display_errors: true
type: rotatingFile database: main_connexion
max_day: 10 template_engine: twig_debug
orm: doctrine_test
cache: array_cache
no_display_errors:
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
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

@@ -0,0 +1,13 @@
main_connexion:
host: hostname
port: port
user: username
password: password
dbname: dbname
driver: pdo_mysql
charset: UTF8
test_connexion:
driver: pdo_sqlite
path: one/path/to/database
charset: UTF8

View File

@@ -1,112 +0,0 @@
environment : dev
dev:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
output: json
type: monolog
handler: rotate
filename: doctrine-query.log
max_day: 2
monolog:
output: json
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
prod:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: false
display_errors: false
database:
host: localhost
port: 3306
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: apc
result: apc
metadata: apc
log:
output: json
enable: true
type: monolog
handler: rotate
filename: sql-query.log
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
test:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
monolog:
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10

View File

@@ -1,108 +0,0 @@
environment : dev
dev:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: root
password: nicolas007
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
type: monolog
handler: rotate
filename: doctrine-query.log
max_day: 2
monolog:
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
prod:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: false
display_errors: false
database:
host: localhost
port: 3306
dbname: ab_trunk
user: root
password: nicolas007
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: apc
result: apc
metadata: apc
log:
enable: true
type: monolog
handler: rotate
filename: sql-query.log
monolog:
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
test:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: root
password: nicolas007
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
monolog:
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10

View File

@@ -1,105 +0,0 @@
environment : dev
dev:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: ab_trunk
user: root
password: nicolas007
doctrine:
dbal:
driver: pdo_sqlite
path: /Users/nicolasl/workspace/phraseanet/lib/unitTest/tests.sqlite
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
type: monolog
handler: rotate
filename: doctrine-query.log
max_day: 2
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
prod:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: false
display_errors: false
database:
driver: pdo_sqlite
path: unpath
charset: UTF8
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: apc
result: apc
metadata: apc
log:
enable: true
type: monolog
handler: rotate
filename: sql-query.log
monolog:
output: yaml
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10
test:
phraseanet:
servername: http://dev.phrasea.net/
maintenance: false
debug: true
display_errors: true
database:
host: localhost
port: 3306
dbname: dbname
user: test
password: test
doctrine:
dbal:
driver: pdo_sqlite
path: unpath
charset: UTF8
orm:
cache:
query: array
result: array
metadata: array
log:
enable: false
monolog:
handlers:
main:
type: stream
rotate:
type: rotatingFile
max_day: 10

View File

@@ -0,0 +1,79 @@
twig:
type: twig
options:
debug: false
charset: utf-8
strict_variables: true
optimizer: true
twig_debug:
type: twig
options:
debug: true
charset: utf-8
strict_variables: true
autoescape: true
optimizer: true
doctrine_dev:
type: doctrine
options:
debug: true
dbal: main_connexion
orm:
cache:
query: array_cache
result: array_cache
metadata: array_cache
log: query_logger
doctrine_test:
type: doctrine
options:
debug: true
dbal: test_connexion
orm:
cache:
query: array_cache
result: array_cache
metadata: array_cache
log: query_logger
doctrine_prod:
type: doctrine
options:
debug: false
dbal: main_connexion
orm:
cache:
query: apc_cache
result: apc_cache
metadata: apc_cache
log: query_logger
query_logger:
type: monolog
options:
output: json
channel: query-logger
max_day: 2
filename: doctrine-query.log
sql_logger:
type: normal
array_cache:
type: array
memcache_cache:
type: memcache
options:
host: localhost
port: 11211
apc_cache:
type: apc
xcache_cache:
type: xcache