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
{
/**
*
* @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()
{
parent::setUp();
}
public function testInitialization()
{
$spec = $this->getMock(
$specNotInstalled = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
);
$fileName = __DIR__ . '/confTestFiles/good.yml';
$spec->expects($this->any())
$specNotInstalled->expects($this->any())
->method('getConfigurationFile')
->will(
$this->returnValue(
new \SplFileObject($fileName)
)
$this->throwException(new Exception)
);
$handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml());
$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(
$specExperience = $this->getMock(
'\Alchemy\Phrasea\Core\Configuration\Application'
, array('getConfigurationFile')
);
$spec->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())
$specExperience->expects($this->any())
->method('getConfigurationFile')
->will(
$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(
// '\Alchemy\Phrasea\Core\Configuration\Application'
// , array('getConfigurationFile')
// );
//
// $fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml';
//
// $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');
//
// $this->object->setEnvironnement("test");
// $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
// $this->object->setEnvironnement("dev");
// $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
// $this->object->setEnvironnement("prod");
// $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag", $this->object->getPhraseanet());
// $this->object->setEnvironnement("missing_phraseanet");
// try
// {
// $configuration->getDoctrine();
// $this->fail('An exception should be raised');
// $this->object->getPhraseanet();
// $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
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
environment: dev
dev:
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: true
display_errors: true
database: main_connexion
template_engine: twig_debug
orm: doctrine_dev
cache: array_cache
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
phraseanet:
servername: 'http://dev.phrasea.net/'
maintenance: false
debug: false
display_errors: false
database: main_connexion
template_engine: twig
orm: doctrine_prod
cache: apc_cache
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
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
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
no_debug:
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
no_maintenance:
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
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