diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php index 3e146bd6ca..c28dc6e954 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php @@ -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) // { // // } // } + } \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/bad_doctrine_logger.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/bad_doctrine_logger.yml deleted file mode 100644 index 05d88ccf6d..0000000000 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/bad_doctrine_logger.yml +++ /dev/null @@ -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 - - - \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/config.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/config.yml index 67d23ba031..29924ae235 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/config.yml +++ b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/config.yml @@ -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 newline at end of file +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 \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/connexions.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/connexions.yml new file mode 100644 index 0000000000..98ab029579 --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/connexions.yml @@ -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 diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good.yml deleted file mode 100644 index 67d23ba031..0000000000 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good.yml +++ /dev/null @@ -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 - - - \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good_no_output.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good_no_output.yml deleted file mode 100644 index ea8fa42312..0000000000 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good_no_output.yml +++ /dev/null @@ -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 - - - \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good_with_no_logger_output.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good_with_no_logger_output.yml deleted file mode 100644 index 47e7d76ef3..0000000000 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/good_with_no_logger_output.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/services.yml b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/services.yml new file mode 100644 index 0000000000..124e678ded --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/confTestFiles/services.yml @@ -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 \ No newline at end of file