From 02a1e4b3b90d2e10f68fa44533be58279d5fb96c Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 23 Jan 2012 18:58:39 +0100 Subject: [PATCH] add testes for service builder --- .../ServiceBuilder/AbstractBuilderTest.php | 64 +++++++++++++++++ .../Core/ServiceBuilder/CacheBuilderTest.php | 50 ++++++++++++++ .../Core/ServiceBuilder/LogBuilderTest.php | 68 +++++++++++++++++++ .../Core/ServiceBuilder/OrmBuilderTest.php | 64 +++++++++++++++++ .../ServiceBuilder/TemplateBuilderTest.php | 50 ++++++++++++++ 5 files changed, 296 insertions(+) create mode 100644 lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php create mode 100644 lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php create mode 100644 lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php create mode 100644 lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php create mode 100644 lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php new file mode 100644 index 0000000000..b60affa39a --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilderTest.php @@ -0,0 +1,64 @@ +getMockForAbstractClass( + "\Alchemy\Phrasea\Core\ServiceBuilder\AbstractBuilder" + , array( + '' + , new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag() + , array('dependency' => 'one_dependency') + , null + ) + ); + $this->fail("should raise an exception"); + } + catch (\Exception $e) + { + + } + } + + public function testConstructExceptionCreate() + { + try + { + $stub = $this->getMockForAbstractClass( + "\Alchemy\Phrasea\Core\ServiceBuilder\AbstractBuilder" + , array( + 'test' + , new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag() + , array('dependency' => 'one_dependency') + , null + ) + ); + $this->fail("should raise an exception"); + } + catch (\Exception $e) + { + + } + } +} \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php new file mode 100644 index 0000000000..c1cc778571 --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php @@ -0,0 +1,50 @@ + "unknow") + ); + + try + { + $service = Alchemy\Phrasea\Core\ServiceBuilder\Cache::create("test", $configuration); + $this->fail("An exception should be raised"); + } + catch (\Exception $e) + { + + } + } + + public function testCreate() + { + $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( + array("type" => "array") + ); + + $service = Alchemy\Phrasea\Core\ServiceBuilder\Cache::create("test", $configuration); + $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); + } + +} \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php new file mode 100644 index 0000000000..e1750dc1ed --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php @@ -0,0 +1,68 @@ + "unknow", "options" => array()) + ); + + try + { + $service = Alchemy\Phrasea\Core\ServiceBuilder\Log::create("test", $configuration); + $this->fail("An exception should be raised"); + } + catch (\Exception $e) + { + + } + } + + public function testCreate() + { + $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( + array("type" => "monolog", "options" => array( + "handler" => "rotate" + , "filename" => "test" + ) + ) + ); + + $service = Alchemy\Phrasea\Core\ServiceBuilder\Log::create("test", $configuration); + $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); + } + + public function testCreateNamespace() + { + $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( + array("type" => "normal", "options" => array( + "handler" => "rotate" + , "filename" => "test" + ) + ) + ); + + $service = Alchemy\Phrasea\Core\ServiceBuilder\Log::create("test", $configuration, array(), "Doctrine"); + $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); + } + +} \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php new file mode 100644 index 0000000000..0b2d544b22 --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php @@ -0,0 +1,64 @@ + "unknow", "options" => array()) + ); + + try + { + $service = Alchemy\Phrasea\Core\ServiceBuilder\Orm::create("test", $configuration); + $this->fail("An exception should be raised"); + } + catch (\Exception $e) + { + + } + } + + public function testCreate() + { + $registry = $this->getMock("\RegistryInterface"); + + $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( + array("type" => "doctrine", "options" => array( + "debug" => false + , "log" => "sql_logger" + , "dbal" => "main_connexion" + , "orm" => array( + "cache" => array( + "metadata" => "array_cache" + , "query" => "array_cache" + , "result" => "array_cache" + ) + ) + ) + ) + ); + + $service = Alchemy\Phrasea\Core\ServiceBuilder\Orm::create("test", $configuration, array("registry" => $registry)); + $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); + } + +} \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php new file mode 100644 index 0000000000..ed52b9218e --- /dev/null +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php @@ -0,0 +1,50 @@ + "unknow", "options" => array()) + ); + + try + { + $service = Alchemy\Phrasea\Core\ServiceBuilder\TemplateEngine::create("test", $configuration); + $this->fail("An exception should be raised"); + } + catch (\Exception $e) + { + + } + } + + public function testCreate() + { + $configuration = new Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( + array("type" => "twig", "options" => array()) + ); + + $service = Alchemy\Phrasea\Core\ServiceBuilder\TemplateEngine::create("test", $configuration); + $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); + } + +} \ No newline at end of file