From 5557d8b8b7bb7c5af296cb91aa0bbe26be9845ed Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 15 Mar 2012 16:43:23 +0100 Subject: [PATCH] refactor service interface --- lib/Alchemy/Phrasea/Cache/Manager.php | 4 +- .../Phrasea/Controller/Setup/Installer.php | 1 - lib/Alchemy/Phrasea/Core.php | 5 +- lib/Alchemy/Phrasea/Core/Service/Builder.php | 16 +---- .../Phrasea/Core/Service/Cache/ApcCache.php | 11 +-- .../Phrasea/Core/Service/Cache/ArrayCache.php | 10 --- .../Core/Service/Cache/MemcacheCache.php | 23 ++----- .../Phrasea/Core/Service/Cache/RedisCache.php | 21 ++---- .../Core/Service/Cache/XcacheCache.php | 10 --- .../Core/Service/Log/Doctrine/Monolog.php | 24 +++---- .../Core/Service/Log/Doctrine/Phpecho.php | 11 --- .../Phrasea/Core/Service/Log/FirePHP.php | 28 ++------ .../Phrasea/Core/Service/Log/Monolog.php | 24 +++---- .../Phrasea/Core/Service/Orm/Doctrine.php | 68 +++++++++---------- .../Phrasea/Core/Service/ServiceAbstract.php | 41 ++++++++--- .../Phrasea/Core/Service/ServiceInterface.php | 6 +- .../Core/Service/TemplateEngine/Twig.php | 15 ++-- .../console/fileEnsureDevSetting.class.php | 10 +-- .../fileEnsureProductionSetting.class.php | 10 +-- .../Core/Service/Cache/ApcCacheTest.php | 15 +--- .../Core/Service/Cache/ArrayCacheTest.php | 15 +--- .../Core/Service/Cache/MemcacheCacheTest.php | 19 ++---- .../Core/Service/Cache/XcacheCacheTest.php | 15 +--- .../Core/Service/Log/Doctrine/MonologTest.php | 21 +++--- .../Core/Service/Log/Doctrine/PhpechoTest.php | 12 +--- .../Phrasea/Core/Service/Log/MonologTest.php | 24 +++---- .../Phrasea/Core/Service/Orm/DoctrineTest.php | 35 ++++------ .../Core/Service/ServiceAbtractTest.php | 8 +-- .../Core/Service/TemplateEngine/TwigTest.php | 21 +++--- .../Core/ServiceBuilder/CacheBuilderTest.php | 4 +- .../Core/ServiceBuilder/LogBuilderTest.php | 6 +- .../Core/ServiceBuilder/OrmBuilderTest.php | 4 +- .../ServiceBuilder/TemplateBuilderTest.php | 4 +- .../PhraseanetPHPUnitAbstract.class.inc | 3 +- 34 files changed, 187 insertions(+), 357 deletions(-) diff --git a/lib/Alchemy/Phrasea/Cache/Manager.php b/lib/Alchemy/Phrasea/Cache/Manager.php index c56a0820b2..be278499bd 100644 --- a/lib/Alchemy/Phrasea/Cache/Manager.php +++ b/lib/Alchemy/Phrasea/Cache/Manager.php @@ -71,7 +71,7 @@ class Manager try { $configuration = $this->core->getConfiguration()->getService($service_name); - $service = Builder::create($this->core, $service_name, $configuration); + $service = Builder::create($this->core, $configuration); $driver = $service->getDriver(); $write = true; } @@ -80,7 +80,7 @@ class Manager $configuration = new \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag( array('type' => 'Cache\\ArrayCache') ); - $service = Builder::create($this->core, $service_name, $configuration); + $service = Builder::create($this->core, $configuration); $driver = $service->getDriver(); $write = false; } diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index bd047d8d85..3348e4819d 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -217,7 +217,6 @@ class Installer implements ControllerProviderInterface $ormService = \Alchemy\Phrasea\Core\Service\Builder::create( $app['Core'] - , $serviceName , $confService ); diff --git a/lib/Alchemy/Phrasea/Core.php b/lib/Alchemy/Phrasea/Core.php index 7316eb1148..b0c0fe1372 100644 --- a/lib/Alchemy/Phrasea/Core.php +++ b/lib/Alchemy/Phrasea/Core.php @@ -94,7 +94,6 @@ class Core extends \Pimple $this['CacheService'] = $this->share(function() use ($core) { - if (!file_exists(__DIR__ . '/../../../tmp/cache_registry.yml')) { touch(__DIR__ . '/../../../tmp/cache_registry.yml'); @@ -112,7 +111,7 @@ class Core extends \Pimple $serviceName = $core->getConfiguration()->getOrm(); $configuration = $core->getConfiguration()->getService($serviceName); - $Service = Core\Service\Builder::create($core, $serviceName, $configuration); + $Service = Core\Service\Builder::create($core, $configuration); return $Service->getDriver(); }); @@ -139,7 +138,7 @@ class Core extends \Pimple $serviceName = $core->getConfiguration()->getTemplating(); $configuration = $core->getConfiguration()->getService($serviceName); - $Service = Core\Service\Builder::create($core, $serviceName, $configuration); + $Service = Core\Service\Builder::create($core, $configuration); return $Service->getDriver(); }); diff --git a/lib/Alchemy/Phrasea/Core/Service/Builder.php b/lib/Alchemy/Phrasea/Core/Service/Builder.php index 044b988a4a..b3f2372af7 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Builder.php +++ b/lib/Alchemy/Phrasea/Core/Service/Builder.php @@ -23,7 +23,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag, class Builder { - public static function create(Core $core, $name, ParameterBag $configuration) + public static function create(Core $core, ParameterBag $configuration) { $classname = __NAMESPACE__ . '\\' . $configuration->get("type"); @@ -41,19 +41,7 @@ class Builder $options = array(); } - $mandatory = $classname::getMandatoryOptions(); - - if ($mandatory !== array_intersect($mandatory, array_keys($options))) - { - throw new Exception\MissingParameters( - sprintf( - 'Missing parameters %s' - , implode(', ', array_diff($mandatory, array_keys($options))) - ) - ); - } - - return new $classname($core, $name, $options); + return new $classname($core, $options); } } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php index 254a335687..a11e92afad 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php @@ -28,11 +28,6 @@ class ApcCache extends ServiceAbstract implements ServiceInterface protected $cache; - public function getScope() - { - return 'cache'; - } - public function getDriver() { if (!extension_loaded('apc')) @@ -55,10 +50,6 @@ class ApcCache extends ServiceAbstract implements ServiceInterface return 'apc'; } - public static function getMandatoryOptions() - { - return array(); - } - + } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php index 919f4bc78b..cae2c51c80 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php @@ -29,11 +29,6 @@ class ArrayCache extends ServiceAbstract implements ServiceInterface protected $cache; - public function getScope() - { - return 'cache'; - } - public function getDriver() { if (!$this->cache) @@ -51,10 +46,5 @@ class ArrayCache extends ServiceAbstract implements ServiceInterface return 'array'; } - public static function getMandatoryOptions() - { - return array(); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php index b0c3ebb533..9ab7c75e4e 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php @@ -26,28 +26,22 @@ use Alchemy\Phrasea\Core, class MemcacheCache extends ServiceAbstract implements ServiceInterface { - protected $cache; - const DEFAULT_HOST = "localhost"; const DEFAULT_PORT = "11211"; + protected $cache; protected $host; protected $port; - public function __construct(Core $core, $name, Array $options) + protected function init() { - parent::__construct( $core, $name, $options); - + $options = $this->getOptions(); + $this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST; $this->port = isset($options["port"]) ? $options["port"] : self::DEFAULT_PORT; } - public function getScope() - { - return 'cache'; - } - public function getDriver() { if (!extension_loaded('memcache')) @@ -55,7 +49,7 @@ class MemcacheCache extends ServiceAbstract implements ServiceInterface throw new \Exception('The Memcache cache requires the Memcache extension.'); } - if(!$this->cache) + if (!$this->cache) { $memcache = new \Memcache(); @@ -70,7 +64,7 @@ class MemcacheCache extends ServiceAbstract implements ServiceInterface $this->cache = new CacheDriver\MemcacheCache(); $this->cache->setMemcache($memcache); - $this->cache->setNamespace(md5(realpath(__DIR__.'/../../../../../../'))); + $this->cache->setNamespace(md5(realpath(__DIR__ . '/../../../../../../'))); } else { @@ -96,10 +90,5 @@ class MemcacheCache extends ServiceAbstract implements ServiceInterface return $this->port; } - public static function getMandatoryOptions() - { - return array('host', 'port'); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/RedisCache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/RedisCache.php index 586ad6b56c..ecc13b661d 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/RedisCache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/RedisCache.php @@ -25,29 +25,23 @@ use Alchemy\Phrasea\Core, */ class RedisCache extends ServiceAbstract implements ServiceInterface { - - protected $cache; - + const DEFAULT_HOST = "localhost"; const DEFAULT_PORT = "6379"; + protected $cache; protected $host; protected $port; - public function __construct(Core $core, $name, Array $options) + protected function init() { - parent::__construct($core, $name, $options); - + $options = $this->getOptions(); + $this->host = isset($options["host"]) ? $options["host"] : self::DEFAULT_HOST; $this->port = isset($options["port"]) ? $options["port"] : self::DEFAULT_PORT; } - public function getScope() - { - return 'cache'; - } - /** * * @return Cache\ApcCache @@ -100,10 +94,5 @@ class RedisCache extends ServiceAbstract implements ServiceInterface return $this->port; } - public static function getMandatoryOptions() - { - return array('host', 'port'); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php index fcdf9af11b..72e5ef85e1 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php @@ -28,11 +28,6 @@ class XcacheCache extends ServiceAbstract implements ServiceInterface protected $cache; - public function getScope() - { - return 'cache'; - } - public function getDriver() { if (!extension_loaded('xcache')) @@ -55,9 +50,4 @@ class XcacheCache extends ServiceAbstract implements ServiceInterface return 'xcache'; } - public static function getMandatoryOptions() - { - return array(); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php index f92f5d2e5e..b631f9a7bc 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php +++ b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php @@ -15,9 +15,9 @@ use Alchemy\Phrasea\Core, Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceInterface; - use Alchemy\Phrasea\Core\Service\Log\Monolog as ParentLog; use Doctrine\Logger\MonologSQLLogger; + /** * * @package @@ -26,27 +26,27 @@ use Doctrine\Logger\MonologSQLLogger; */ class Monolog extends ParentLog implements ServiceInterface { + const JSON_OUTPUT = 'json'; const YAML_OUTPUT = 'yaml'; const VAR_DUMP_OUTPUT = 'vdump'; - protected $outputs = array( - self::JSON_OUTPUT, self::YAML_OUTPUT, self::VAR_DUMP_OUTPUT - ); - public function getDriver() { $output = isset($this->options["output"]) ? $this->options["output"] : self::JSON_OUTPUT; - if (!in_array($output, $this->outputs)) + $outputs = array( + self::JSON_OUTPUT, self::YAML_OUTPUT, self::VAR_DUMP_OUTPUT + ); + + if (!in_array($output, $outputs)) { throw new \Exception(sprintf( - "The output type '%s' declared in %s %s service is not valid. + "The output type '%s' declared in %s service is not valid. Available types are %s." , $output - , $this->name - , $this->getScope() - , implode(", ", $this->outputs) + , __CLASS__ + , implode(", ", $outputs) ) ); } @@ -59,9 +59,5 @@ class Monolog extends ParentLog implements ServiceInterface return 'doctrine_monolog'; } - public static function getMandatoryOptions() - { - return array('output', 'channel', 'handler', 'max_day', 'filename'); - } } diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Phpecho.php b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Phpecho.php index 6e1369f09a..4432bbe51c 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Phpecho.php +++ b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Phpecho.php @@ -26,7 +26,6 @@ use Doctrine\DBAL\Logging\EchoSQLLogger; class Phpecho extends ServiceAbstract implements ServiceInterface { - public function getDriver() { return new EchoSQLLogger(); @@ -37,14 +36,4 @@ class Phpecho extends ServiceAbstract implements ServiceInterface return 'phpecho'; } - public function getScope() - { - return 'log'; - } - - public static function getMandatoryOptions() - { - return array(); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/FirePHP.php b/lib/Alchemy/Phrasea/Core/Service/Log/FirePHP.php index 071c819560..c1da3e8f39 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Log/FirePHP.php +++ b/lib/Alchemy/Phrasea/Core/Service/Log/FirePHP.php @@ -29,19 +29,15 @@ class FirePHP extends ServiceAbstract implements ServiceInterface protected $logger; - public function __construct(\Alchemy\Phrasea\Core $core, $name, Array $options) - { - parent::__construct($core, $name, $options); - - $this->logger = new Logger('FirePHP'); - - $this->logger->pushHandler(new FirePHPHandler()); - - return $this; - } - public function getDriver() { + if (!$this->logger) + { + $this->logger = new Logger('FirePHP'); + + $this->logger->pushHandler(new FirePHPHandler()); + } + return $this->logger; } @@ -50,14 +46,4 @@ class FirePHP extends ServiceAbstract implements ServiceInterface return 'FirePHP Monolog'; } - public function getScope() - { - return 'log'; - } - - public static function getMandatoryOptions() - { - return array(); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php b/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php index 438cac0ec2..d721b8e191 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php +++ b/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php @@ -37,10 +37,10 @@ class Monolog extends ServiceAbstract implements ServiceInterface */ protected $monolog; - public function __construct(Core $core, $name, Array $options) + protected function init() { - parent::__construct( $core, $name, $options); - + $options = $this->getOptions(); + if (empty($options)) { throw new \Exception(sprintf("'%s' service options can not be empty", $this->name)); @@ -52,8 +52,8 @@ class Monolog extends ServiceAbstract implements ServiceInterface if (!$handler) { throw new \Exception(sprintf( - "You must specify at least one handler for %s service" - , $this->name + "You must specify at least one handler for '%s' service" + , __CLASS__ ) ); } @@ -64,8 +64,7 @@ class Monolog extends ServiceAbstract implements ServiceInterface "The handler type '%s' declared in %s %s service is not valid. Available types are %s." , $handler - , $this->name - , $this->getScope() + , __CLASS__ , implode(", ", $this->handlers) ) ); @@ -88,7 +87,7 @@ class Monolog extends ServiceAbstract implements ServiceInterface { throw new \Exception(sprintf( "Missing filename option in '%s' service" - , $this->name + , __CLASS__ ) ); } @@ -129,14 +128,9 @@ class Monolog extends ServiceAbstract implements ServiceInterface return 'monolog'; } - public function getScope() + public function getMandatoryOptions() { - return 'log'; - } - - public static function getMandatoryOptions() - { - return array('output', 'channel', 'handler', 'max_day', 'filename'); + return array('channel', 'handler', 'filename'); } } diff --git a/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php b/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php index 11ad9c4054..45b94cdae8 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php +++ b/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php @@ -27,19 +27,17 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class Doctrine extends ServiceAbstract implements ServiceInterface { - protected $outputs = array( - 'json', 'yaml', 'vdump' - ); protected $loggers = array( - 'Log\\Doctrine\Monolog', 'Log\\Doctrine\\Phpecho' + 'Log\\Doctrine\Monolog' + , 'Log\\Doctrine\\Phpecho' ); protected $entityManager; protected $debug; - public function __construct(Core $core, $name, Array $options) + protected function init() { - parent::__construct($core, $name, $options); - + $options = $this->getOptions(); + $config = new \Doctrine\ORM\Configuration(); $this->debug = !!$options["debug"]; @@ -55,16 +53,16 @@ class Doctrine extends ServiceAbstract implements ServiceInterface if (!$cache || $this->debug) { - $metaCache = $this->core['CacheService']->get('ORMmetadata', 'Cache\\ArrayCache'); - $queryCache = $this->core['CacheService']->get('ORMquery', 'Cache\\ArrayCache'); + $metaCache = $this->core['CacheService']->get('ORMmetadata', 'Cache\\ArrayCache'); + $queryCache = $this->core['CacheService']->get('ORMquery', 'Cache\\ArrayCache'); } else { - $query = isset($cache["query"]['service']) ? $cache["query"]['service'] : 'Cache\\ArrayCache'; - $meta = isset($cache["metadata"]['service']) ? $cache["metadata"]['service'] : 'Cache\\ArrayCache'; + $query = isset($cache["query"]['service']) ? $cache["query"]['service'] : 'Cache\\ArrayCache'; + $meta = isset($cache["metadata"]['service']) ? $cache["metadata"]['service'] : 'Cache\\ArrayCache'; - $queryCache = $this->core['CacheService']->get('ORMquery', $query); - $metaCache = $this->core['CacheService']->get('ORMmetadata', $meta); + $queryCache = $this->core['CacheService']->get('ORMquery', $query); + $metaCache = $this->core['CacheService']->get('ORMmetadata', $meta); } $resultCache = $this->core['CacheService']->get('ORMresult', 'Cache\\ArrayCache'); @@ -81,7 +79,7 @@ class Doctrine extends ServiceAbstract implements ServiceInterface $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $driverYaml = new \Doctrine\ORM\Mapping\Driver\YamlDriver( - array(__DIR__ . '/../../../../../conf.d/Doctrine') + array(__DIR__ . '/../../../../../conf.d/Doctrine') ); $chainDriverImpl->addDriver($driverYaml, 'Entities'); @@ -99,9 +97,9 @@ class Doctrine extends ServiceAbstract implements ServiceInterface if (!$connexion) { throw new \Exception(sprintf( - "Missing dbal configuration for '%s' service" - , __CLASS__ - ) + "Missing dbal configuration for '%s' service" + , __CLASS__ + ) ); } @@ -125,9 +123,9 @@ class Doctrine extends ServiceAbstract implements ServiceInterface catch (\Exception $e) { throw new \Exception(sprintf( - "Failed to create doctrine service for the following reason '%s'" - , $e->getMessage() - ) + "Failed to create doctrine service for the following reason '%s'" + , $e->getMessage() + ) ); } @@ -184,11 +182,13 @@ class Doctrine extends ServiceAbstract implements ServiceInterface catch (\Exception $e) { $message = sprintf( - "%s from %s service in orm:log scope" - , $e->getMessage() - , $this->name + "%s from %s service" + , $e->getMessage() + , __CLASS__ ); - $e = new \Exception($message); + + $e = new \Exception($message); + throw $e; } @@ -197,17 +197,16 @@ class Doctrine extends ServiceAbstract implements ServiceInterface if (!in_array($type, $this->loggers)) { throw new \Exception(sprintf( - "The logger type '%s' declared in %s %s service is not valid. + "The logger type '%s' declared in %s service is not valid. Available types are %s." - , $type - , $this->name - , $this->getScope() - , implode(", ", $this->loggers) - ) + , $type + , __CLASS__ + , implode(", ", $this->loggers) + ) ); } - $service = Core\Service\Builder::create($this->core, $serviceName, $configuration); + $service = Core\Service\Builder::create($this->core, $configuration); return $service->getDriver(); } @@ -222,17 +221,12 @@ class Doctrine extends ServiceAbstract implements ServiceInterface return 'doctrine'; } - public function getScope() - { - return 'orm'; - } - public function isDebug() { return $this->debug; } - public static function getMandatoryOptions() + public function getMandatoryOptions() { return array('debug', 'dbal'); } diff --git a/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php b/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php index 61ddc11043..954dc4cc17 100644 --- a/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php +++ b/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php @@ -23,25 +23,37 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; abstract class ServiceAbstract { - protected $name; protected $core; protected $options; - protected $configuration; - public function __construct(Core $core, $name, Array $options) + final public function __construct(Core $core, Array $options) { $this->core = $core; - $this->name = $name; $this->options = $options; + + $mandatory = $this->getMandatoryOptions(); + + if ($mandatory !== array_intersect($mandatory, array_keys($options))) + { + throw new Exception\MissingParameters( + sprintf( + 'Missing parameters %s' + , implode(', ', array_diff($mandatory, array_keys($options))) + ) + ); + } + + $this->init(); } - /** - * - * @return string - */ - public function getName() + protected function init() { - return $this->name; + return; + } + + protected function getCore() + { + return $this->core; } /** @@ -53,6 +65,13 @@ abstract class ServiceAbstract return $this->options; } - abstract public static function getMandatoryOptions(); + /** + * + * @return Array + */ + public function getMandatoryOptions() + { + return array(); + } } diff --git a/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php b/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php index 7e08bef778..f6f68a28c7 100644 --- a/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php +++ b/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php @@ -20,14 +20,12 @@ namespace Alchemy\Phrasea\Core\Service; interface ServiceInterface { - public function getName(); - public function getType(); public function getDriver(); public function getOptions(); - - public function getScope(); + + public function getMandatoryOptions(); } diff --git a/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php b/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php index 4d7f92ab6d..6b2c20ff35 100644 --- a/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php +++ b/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php @@ -26,15 +26,13 @@ class Twig extends ServiceAbstract implements ServiceInterface protected $twig; protected $templatesPath = array(); - public function __construct(Core $core, $name, Array $options) + protected function init() { - parent::__construct( $core, $name, $options); - $this->templatesPath = $this->resolvePaths(); try { - if (!isset($this->options['debug']) || !$this->options['debug']) + if (!$this->options['debug']) { $this->options['cache'] = realpath(__DIR__ . '/../../../../../../tmp/cache_twig/'); } @@ -50,7 +48,7 @@ class Twig extends ServiceAbstract implements ServiceInterface { throw new \Exception(sprintf( "Unable to create '%s' service for the following reason %s" - , $this->name + , __CLASS__ , $e->getMessage() ) ); @@ -207,12 +205,7 @@ class Twig extends ServiceAbstract implements ServiceInterface return 'twig'; } - public function getScope() - { - return 'template_engine'; - } - - public static function getMandatoryOptions() + public function getMandatoryOptions() { return array('debug', 'charset', 'strict_variables', 'autoescape', 'optimizer'); } diff --git a/lib/classes/module/console/fileEnsureDevSetting.class.php b/lib/classes/module/console/fileEnsureDevSetting.class.php index 8583dd0707..01e8cf8056 100644 --- a/lib/classes/module/console/fileEnsureDevSetting.class.php +++ b/lib/classes/module/console/fileEnsureDevSetting.class.php @@ -466,7 +466,7 @@ class module_console_fileEnsureDevSetting extends Command try { - Core\Service\Builder::create(\bootstrap::getCore(), $templateEngineName, $configuration); + Core\Service\Builder::create(\bootstrap::getCore(), $configuration); $work_message = 'Works !'; } catch (\Exception $e) @@ -592,7 +592,7 @@ class module_console_fileEnsureDevSetting extends Command try { - $service = Core\Service\Builder::create(\bootstrap::getCore(), $ormName, $configuration); + $service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration); $work_message = 'Works !'; } catch (\Exception $e) @@ -774,7 +774,7 @@ class module_console_fileEnsureDevSetting extends Command $conf = $this->configuration->getService($ServiceName); $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $conf + \bootstrap::getCore(), $conf ); } catch (\Exception $e) @@ -845,7 +845,7 @@ class module_console_fileEnsureDevSetting extends Command $originalConfiguration = $this->configuration->getService($ServiceName); $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $originalConfiguration + \bootstrap::getCore(), $originalConfiguration ); } catch (\Exception $e) @@ -879,7 +879,7 @@ class module_console_fileEnsureDevSetting extends Command $originalConfiguration = $this->configuration->getService($ServiceName); $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $originalConfiguration + \bootstrap::getCore(), $originalConfiguration ); } catch (\Exception $e) diff --git a/lib/classes/module/console/fileEnsureProductionSetting.class.php b/lib/classes/module/console/fileEnsureProductionSetting.class.php index b5e87c5f63..3716bb6972 100644 --- a/lib/classes/module/console/fileEnsureProductionSetting.class.php +++ b/lib/classes/module/console/fileEnsureProductionSetting.class.php @@ -460,7 +460,7 @@ class module_console_fileEnsureProductionSetting extends Command try { - Core\Service\Builder::create(\bootstrap::getCore(), $templateEngineName, $configuration); + Core\Service\Builder::create(\bootstrap::getCore(), $configuration); $work_message = 'Works !'; } catch (\Exception $e) @@ -586,7 +586,7 @@ class module_console_fileEnsureProductionSetting extends Command try { - $service = Core\Service\Builder::create(\bootstrap::getCore(), $ormName, $configuration); + $service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration); $work_message = 'Works !'; } catch (\Exception $e) @@ -781,7 +781,7 @@ class module_console_fileEnsureProductionSetting extends Command $conf = $this->configuration->getService($ServiceName); $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $conf + \bootstrap::getCore(), $conf ); } catch (\Exception $e) @@ -852,7 +852,7 @@ class module_console_fileEnsureProductionSetting extends Command $originalConfiguration = $this->configuration->getService($ServiceName); $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $originalConfiguration + \bootstrap::getCore(), $originalConfiguration ); } catch (\Exception $e) @@ -886,7 +886,7 @@ class module_console_fileEnsureProductionSetting extends Command $originalConfiguration = $this->configuration->getService($ServiceName); $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $originalConfiguration + \bootstrap::getCore(), $originalConfiguration ); } catch (\Exception $e) diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ApcCacheTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ApcCacheTest.php index cbd19d9af6..96763cb2e9 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ApcCacheTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ApcCacheTest.php @@ -20,19 +20,10 @@ require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; class ServiceApcCacheTest extends PhraseanetPHPUnitAbstract { - public function testScope() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache( - self::$core, 'hello', array() - ); - - $this->assertEquals("cache", $cache->getScope()); - } - public function testService() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache( - self::$core, 'hello', array() + self::$core, array() ); if (extension_loaded('apc')) @@ -57,7 +48,7 @@ class ServiceApcCacheTest extends PhraseanetPHPUnitAbstract public function testServiceException() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache( - self::$core, 'hello', array() + self::$core, array() ); try @@ -74,7 +65,7 @@ class ServiceApcCacheTest extends PhraseanetPHPUnitAbstract public function testType() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\ApcCache( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals("apc", $cache->getType()); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ArrayCacheTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ArrayCacheTest.php index 497c700e30..eca02e8da8 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ArrayCacheTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/ArrayCacheTest.php @@ -20,19 +20,10 @@ require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; class ServiceArrayCacheTest extends PhraseanetPHPUnitAbstract { - public function testScope() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( - self::$core, 'hello', array() - ); - - $this->assertEquals("cache", $cache->getScope()); - } - public function testService() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( - self::$core, 'hello', array() + self::$core, array() ); $service = $cache->getDriver(); @@ -42,7 +33,7 @@ class ServiceArrayCacheTest extends PhraseanetPHPUnitAbstract public function testServiceException() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( - self::$core, 'hello', array() + self::$core, array() ); try @@ -59,7 +50,7 @@ class ServiceArrayCacheTest extends PhraseanetPHPUnitAbstract public function testType() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\ArrayCache( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals("array", $cache->getType()); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/MemcacheCacheTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/MemcacheCacheTest.php index a1d6bae9b8..c7b8c4f77c 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/MemcacheCacheTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/MemcacheCacheTest.php @@ -20,19 +20,10 @@ require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract { - public function testScope() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$core, 'hello', array() - ); - - $this->assertEquals("cache", $cache->getScope()); - } - public function testService() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$core, 'hello', array() + self::$core, array() ); if (extension_loaded('memcache')) @@ -57,7 +48,7 @@ class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract public function testServiceException() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$core, 'hello', array() + self::$core, array() ); try @@ -74,7 +65,7 @@ class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract public function testType() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals("memcache", $cache->getType()); @@ -83,7 +74,7 @@ class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract public function testHost() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_HOST, $cache->getHost()); @@ -92,7 +83,7 @@ class ServiceMemcacheCacheTest extends PhraseanetPHPUnitAbstract public function testPort() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\MemcacheCache( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals(\Alchemy\Phrasea\Core\Service\Cache\MemcacheCache::DEFAULT_PORT, $cache->getPort()); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/XcacheCacheTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/XcacheCacheTest.php index d478f7a8a1..68fba58f0c 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/XcacheCacheTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Cache/XcacheCacheTest.php @@ -20,19 +20,10 @@ require_once __DIR__ . '/../../../../../PhraseanetPHPUnitAbstract.class.inc'; class ServiceXcacheCacheTest extends PhraseanetPHPUnitAbstract { - public function testScope() - { - $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache( - self::$core, 'hello', array() - ); - - $this->assertEquals("cache", $cache->getScope()); - } - public function testService() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache( - self::$core, 'hello', array() + self::$core, array() ); if (extension_loaded('xcache')) @@ -57,7 +48,7 @@ class ServiceXcacheCacheTest extends PhraseanetPHPUnitAbstract public function testServiceException() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache( - self::$core, 'hello', array() + self::$core, array() ); try @@ -74,7 +65,7 @@ class ServiceXcacheCacheTest extends PhraseanetPHPUnitAbstract public function testType() { $cache = new \Alchemy\Phrasea\Core\Service\Cache\XcacheCache( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals("xcache", $cache->getType()); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/MonologTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/MonologTest.php index 1aba32690d..20c2829939 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/MonologTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/MonologTest.php @@ -20,26 +20,23 @@ require_once __DIR__ . '/../../../../../../PhraseanetPHPUnitAbstract.class.inc'; class DoctrineMonologTest extends PhraseanetPHPUnitAbstract { - protected $options = array( - "handler" => "rotate" - , "filename" => "test" - ); + protected $options = array( + "handler" => "rotate" + , "filename" => "test" + , 'output' => 'json' + , 'channel' => 'test' + ); public function setUp() { parent::setUp(); - $this->options = array( - "handler" => "rotate" - , "filename" => "test" - , 'output' => 'json' - ); } public function testService() { $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Doctrine\Logger\MonologSQLLogger", $log->getDriver()); @@ -48,7 +45,7 @@ class DoctrineMonologTest extends PhraseanetPHPUnitAbstract public function testType() { $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertEquals("doctrine_monolog", $log->getType()); @@ -60,7 +57,7 @@ class DoctrineMonologTest extends PhraseanetPHPUnitAbstract { $this->options["output"] = "unknowOutput"; $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $log->getDriver(); $this->fail("should raise an exception"); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php index c6f13fb0fa..ebb4b9f950 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/Doctrine/PhpechoTest.php @@ -24,7 +24,7 @@ class DoctrinePhpechoTest extends PhraseanetPHPUnitAbstract { $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho( - self::$core, 'hello', array() + self::$core, array() ); $this->assertInstanceOf("\Doctrine\DBAL\Logging\EchoSQLLogger", $log->getDriver()); @@ -33,18 +33,10 @@ class DoctrinePhpechoTest extends PhraseanetPHPUnitAbstract public function testType() { $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho( - self::$core, 'hello', array() + self::$core, array() ); $this->assertEquals("phpecho", $log->getType()); } - public function testScope() - { - $log = new \Alchemy\Phrasea\Core\Service\Log\Doctrine\Phpecho( - self::$core, 'hello', array() - ); - $this->assertEquals("log", $log->getScope()); - } - } diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/MonologTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/MonologTest.php index 5633e543bb..4ce16b5aae 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/MonologTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Log/MonologTest.php @@ -28,23 +28,15 @@ class MonologTest extends PhraseanetPHPUnitAbstract $this->options = array( "handler" => "rotate" , "filename" => "test" + , "channel" => "test" ); } - public function testScope() - { - - $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options - ); - - $this->assertEquals("log", $log->getScope()); - } public function testService() { $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Monolog\Logger", $log->getDriver()); @@ -53,7 +45,7 @@ class MonologTest extends PhraseanetPHPUnitAbstract public function testType() { $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertEquals("monolog", $log->getType()); @@ -64,7 +56,7 @@ class MonologTest extends PhraseanetPHPUnitAbstract try { $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -80,7 +72,7 @@ class MonologTest extends PhraseanetPHPUnitAbstract { unset($this->options["handler"]); $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -96,7 +88,7 @@ class MonologTest extends PhraseanetPHPUnitAbstract { $this->options["handler"] = "unknowHandler"; $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -112,7 +104,7 @@ class MonologTest extends PhraseanetPHPUnitAbstract { unset($this->options["filename"]); $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -127,7 +119,7 @@ class MonologTest extends PhraseanetPHPUnitAbstract $this->options["handler"] = "stream"; $log = new \Alchemy\Phrasea\Core\Service\Log\Monolog( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Monolog\Logger", $log->getDriver()); } diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/Orm/DoctrineTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/Orm/DoctrineTest.php index 76751f9a74..3f732cb07e 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/Orm/DoctrineTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/Orm/DoctrineTest.php @@ -37,19 +37,10 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract ); } - public function testScope() - { - $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options - ); - - $this->assertEquals("orm", $doctrine->getScope()); - } - public function testService() { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Doctrine\ORM\EntityManager", $doctrine->getDriver()); @@ -58,7 +49,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract public function testType() { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertEquals("doctrine", $doctrine->getType()); @@ -69,7 +60,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract try { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -84,7 +75,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract $this->markTestSkipped('To rewrite'); unset($this->options["cache"]); $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); foreach ($doctrine->getCacheServices()->all() as $service) @@ -100,7 +91,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract try { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("An exception should be raised"); } @@ -113,14 +104,14 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract public function testIsDebug() { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertFalse($doctrine->isDebug()); $this->options['debug'] = true; $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertTrue($doctrine->isDebug()); @@ -130,7 +121,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract { $this->markTestSkipped('To rewrite'); $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag" , $doctrine->getCacheServices()); @@ -149,7 +140,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract if (extension_loaded("apc") && extension_loaded("xcache")) { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag" , $doctrine->getCacheServices()); @@ -169,7 +160,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract try { $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("An exception should be raised"); } @@ -186,7 +177,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract { $this->options["log"] = "unknowLogger"; $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -202,7 +193,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract { unset($this->options["dbal"]); $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } @@ -218,7 +209,7 @@ class DoctrineTest extends PhraseanetPHPUnitAbstract { $this->options["dbal"] = "unknowDbal"; $doctrine = new \Alchemy\Phrasea\Core\Service\Orm\Doctrine( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->fail("should raise an exception"); } diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/ServiceAbtractTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/ServiceAbtractTest.php index 01004703be..4eda06158e 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/ServiceAbtractTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/ServiceAbtractTest.php @@ -32,8 +32,7 @@ class ServiceAbstractTest extends PhraseanetPHPUnitAbstract $stub = $this->getMockForAbstractClass( "\Alchemy\Phrasea\Core\Service\ServiceAbstract" , array( - self::$core, - 'abstract' + self::$core , array('option' => 'my_options') ) ); @@ -41,11 +40,6 @@ class ServiceAbstractTest extends PhraseanetPHPUnitAbstract $this->object = $stub; } - public function testGetName() - { - $this->assertEquals("abstract", $this->object->getName()); - } - public function testGetOptions() { $this->assertTrue(is_array($this->object->getOptions())); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/TemplateEngine/TwigTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/TemplateEngine/TwigTest.php index e74e27a60b..49fc8de7c4 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/TemplateEngine/TwigTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Service/TemplateEngine/TwigTest.php @@ -25,22 +25,19 @@ class TwigTest extends PhraseanetPHPUnitAbstract public function setUp() { parent::setUp(); - $this->options = array(); - } - - public function testScope() - { - $doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig( - self::$core, 'hello', $this->options + $this->options = array( + 'debug' => true + ,'charset' => 'utf-8' + ,'strict_variables' => true + ,'autoescape' => true + ,'optimizer' => true ); - - $this->assertEquals("template_engine", $doctrine->getScope()); } public function testService() { $doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Twig_Environment", $doctrine->getDriver()); @@ -49,7 +46,7 @@ class TwigTest extends PhraseanetPHPUnitAbstract public function testServiceExcpetion() { $doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertInstanceOf("\Twig_Environment", $doctrine->getDriver()); @@ -58,7 +55,7 @@ class TwigTest extends PhraseanetPHPUnitAbstract public function testType() { $doctrine = new \Alchemy\Phrasea\Core\Service\TemplateEngine\Twig( - self::$core, 'hello', $this->options + self::$core, $this->options ); $this->assertEquals("twig", $doctrine->getType()); diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php index 135f1e5d56..b72c3a89af 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/CacheBuilderTest.php @@ -28,7 +28,7 @@ class CacheBuilderTest extends PhraseanetPHPUnitAbstract try { - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->fail("An exception should be raised"); } catch (\Exception $e) @@ -43,7 +43,7 @@ class CacheBuilderTest extends PhraseanetPHPUnitAbstract array("type" => "Cache\\ArrayCache") ); - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); } diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php index 5efb402c94..ac71b8851c 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/LogBuilderTest.php @@ -28,7 +28,7 @@ class LogBuilderTest extends PhraseanetPHPUnitAbstract try { - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->fail("An exception should be raised"); } catch (\Exception $e) @@ -50,7 +50,7 @@ class LogBuilderTest extends PhraseanetPHPUnitAbstract ) ); - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); } @@ -60,7 +60,7 @@ class LogBuilderTest extends PhraseanetPHPUnitAbstract array("type" => "Log\\Doctrine\\Phpecho", "options" => array()) ); - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); } diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php index 80fe7e1eef..fed9088119 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/OrmBuilderTest.php @@ -28,7 +28,7 @@ class OrmBuilderTest extends PhraseanetPHPUnitAbstract try { - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->fail("An exception should be raised"); } catch (\Exception $e) @@ -55,7 +55,7 @@ class OrmBuilderTest extends PhraseanetPHPUnitAbstract ) ); - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); } diff --git a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php index 671e318004..b2aea9c3bd 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/ServiceBuilder/TemplateBuilderTest.php @@ -28,7 +28,7 @@ class TemplateBuilderTest extends PhraseanetPHPUnitAbstract try { - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->fail("An exception should be raised"); } catch (\Exception $e) @@ -51,7 +51,7 @@ class TemplateBuilderTest extends PhraseanetPHPUnitAbstract )) ); - $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, "test", $configuration); + $service = Alchemy\Phrasea\Core\Service\Builder::create(self::$core, $configuration); $this->assertInstanceOf("\Alchemy\Phrasea\Core\Service\ServiceAbstract", $service); } diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index 3144bb1e4b..abfb7b61e6 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -822,8 +822,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $confService = $configuration->getService($serviceName); $templateService = \Alchemy\Phrasea\Core\Service\Builder::create( - self::$core, - $serviceName + self::$core , $confService );