diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cron/task_provider_test.php | 50 | ||||
-rw-r--r-- | tests/di/create_container_test.php | 72 | ||||
-rw-r--r-- | tests/di/fixtures/config.php | 11 | ||||
-rw-r--r-- | tests/event/dispatcher_test.php | 2 | ||||
-rw-r--r-- | tests/mock/container_builder.php | 160 |
5 files changed, 244 insertions, 51 deletions
diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php deleted file mode 100644 index ec853bb3ba..0000000000 --- a/tests/cron/task_provider_test.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2010 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->tasks = array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', - ); - - $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface'); - $container - ->expects($this->once()) - ->method('findTaggedServiceIds') - ->will($this->returnValue(array_flip($this->tasks))); - $container - ->expects($this->any()) - ->method('get') - ->will($this->returnCallback(function ($name) { - return new $name; - })); - - $this->provider = new phpbb_cron_task_provider($container); - } - - public function test_manager_finds_shipped_tasks() - { - $task_names = array(); - foreach ($this->provider as $task) - { - $task_names[] = $task->get_name(); - } - sort($task_names); - - $this->assertEquals(array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', - ), $task_names); - } -} diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php new file mode 100644 index 0000000000..c2b8a0fc0b --- /dev/null +++ b/tests/di/create_container_test.php @@ -0,0 +1,72 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php'; + +class phpbb_di_container_test extends phpbb_test_case +{ + public function test_phpbb_create_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), + new phpbb_di_extension_core($phpbb_root_path), + ); + $container = phpbb_create_container($extensions, $phpbb_root_path, 'php'); + + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + } + + public function test_phpbb_create_install_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), + new phpbb_di_extension_core($phpbb_root_path), + ); + $container = phpbb_create_install_container($phpbb_root_path, 'php'); + + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertTrue($container->isFrozen()); + } + + public function test_phpbb_create_compiled_container() + { + $phpbb_root_path = __DIR__ . '/../../phpBB/'; + $extensions = array( + new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'), + new phpbb_di_extension_core($phpbb_root_path), + ); + $container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php'); + + $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container); + $this->assertTrue($container->isFrozen()); + } +} + +class dbal_container_mock extends dbal +{ + public function sql_connect() + { + } + + public function sql_query() + { + } + + public function sql_fetchrow() + { + } + + public function sql_freeresult() + { + } +} diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php new file mode 100644 index 0000000000..5033d2dc9f --- /dev/null +++ b/tests/di/fixtures/config.php @@ -0,0 +1,11 @@ +<?php +// phpBB 3.1.x auto-generated configuration file +// Do not change anything in this file! +$dbms = 'container_mock'; +$dbhost = '127.0.0.1'; +$dbport = ''; +$dbname = 'phpbb'; +$dbuser = 'root'; +$dbpasswd = ''; +$table_prefix = 'phpbb_'; +$acm_type = 'phpbb_cache_driver_null'; diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php index f8fe060d99..9b9203e06a 100644 --- a/tests/event/dispatcher_test.php +++ b/tests/event/dispatcher_test.php @@ -11,7 +11,7 @@ class phpbb_event_dispatcher_test extends phpbb_test_case { public function test_trigger_event() { - $dispatcher = new phpbb_event_dispatcher(); + $dispatcher = new phpbb_event_dispatcher(new phpbb_mock_container_builder()); $dispatcher->addListener('core.test_event', function (phpbb_event_data $event) { $event['foo'] = $event['foo'] . '2'; diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php new file mode 100644 index 0000000000..8a81dd72d1 --- /dev/null +++ b/tests/mock/container_builder.php @@ -0,0 +1,160 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\ScopeInterface; + +class phpbb_mock_container_builder implements ContainerInterface +{ + /** + * Sets a service. + * + * @param string $id The service identifier + * @param object $service The service instance + * @param string $scope The scope of the service + * + * @api + */ + public function set($id, $service, $scope = self::SCOPE_CONTAINER) + { + } + + /** + * Gets a service. + * + * @param string $id The service identifier + * @param int $invalidBehavior The behavior when the service does not exist + * + * @return object The associated service + * + * @throws InvalidArgumentException if the service is not defined + * @throws ServiceCircularReferenceException When a circular reference is detected + * @throws ServiceNotFoundException When the service is not defined + * + * @see Reference + * + * @api + */ + public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) + { + } + + /** + * Returns true if the given service is defined. + * + * @param string $id The service identifier + * + * @return Boolean true if the service is defined, false otherwise + * + * @api + */ + public function has($id) + { + } + + /** + * Gets a parameter. + * + * @param string $name The parameter name + * + * @return mixed The parameter value + * + * @throws InvalidArgumentException if the parameter is not defined + * + * @api + */ + public function getParameter($name) + { + } + + /** + * Checks if a parameter exists. + * + * @param string $name The parameter name + * + * @return Boolean The presence of parameter in container + * + * @api + */ + public function hasParameter($name) + { + } + + /** + * Sets a parameter. + * + * @param string $name The parameter name + * @param mixed $value The parameter value + * + * @api + */ + public function setParameter($name, $value) + { + } + + /** + * Enters the given scope + * + * @param string $name + * + * @api + */ + public function enterScope($name) + { + } + + /** + * Leaves the current scope, and re-enters the parent scope + * + * @param string $name + * + * @api + */ + public function leaveScope($name) + { + } + + /** + * Adds a scope to the container + * + * @param ScopeInterface $scope + * + * @api + */ + public function addScope(ScopeInterface $scope) + { + } + + /** + * Whether this container has the given scope + * + * @param string $name + * + * @return Boolean + * + * @api + */ + public function hasScope($name) + { + } + + /** + * Determines whether the given scope is currently active. + * + * It does however not check if the scope actually exists. + * + * @param string $name + * + * @return Boolean + * + * @api + */ + public function isScopeActive($name) + { + } +} |