diff options
Diffstat (limited to 'tests/di')
-rw-r--r-- | tests/di/create_container_test.php | 14 | ||||
-rw-r--r-- | tests/di/fixtures/config/production/container/environment.yml | 3 | ||||
-rw-r--r-- | tests/di/fixtures/config/test/container/environment.yml | 3 | ||||
-rw-r--r-- | tests/di/fixtures/ext/vendor/enabled_4/environment.yml | 2 | ||||
-rw-r--r-- | tests/di/ordered_service_collection_test.php | 2 | ||||
-rw-r--r-- | tests/di/service_collection_test.php | 27 |
6 files changed, 48 insertions, 3 deletions
diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 1fd2cbd7ee..16b49d1f17 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -26,7 +26,7 @@ namespace protected $phpbb_root_path; protected $filename; - public function setUp() + public function setUp(): void { $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->config_php = new \phpbb\config_php_file($this->phpbb_root_path . 'fixtures/', 'php'); @@ -77,6 +77,18 @@ namespace $this->assertTrue($container->isFrozen()); } + public function test_tables_mapping() + { + $this->builder->without_cache(); + $container = $this->builder->get_container(); + $this->assertTrue($container->hasParameter('tables')); + $tables = $container->getParameter('tables'); + $this->assertGreaterThan(0, count($tables)); + $this->assertTrue($container->hasParameter('tables.foo_bar')); + $this->assertTrue(isset($tables['foo_bar'])); + $this->assertEquals($tables['acl_groups'], 'phpbb_some_other'); + } + public function test_without_cache() { $this->builder->without_cache(); diff --git a/tests/di/fixtures/config/production/container/environment.yml b/tests/di/fixtures/config/production/container/environment.yml index 8281d9e941..0af08f0849 100644 --- a/tests/di/fixtures/config/production/container/environment.yml +++ b/tests/di/fixtures/config/production/container/environment.yml @@ -1,5 +1,8 @@ parameters: core: true + tables.acl_groups: '%core.table_prefix%acl_groups' + tables.acl_options: '%core.table_prefix%acl_options' + tables.acl_roles: '%core.table_prefix%acl_roles' services: config.php: diff --git a/tests/di/fixtures/config/test/container/environment.yml b/tests/di/fixtures/config/test/container/environment.yml index 252117dd32..0a9e4b5e77 100644 --- a/tests/di/fixtures/config/test/container/environment.yml +++ b/tests/di/fixtures/config/test/container/environment.yml @@ -1,5 +1,8 @@ parameters: core: true + tables.acl_groups: '%core.table_prefix%acl_groups' + tables.acl_options: '%core.table_prefix%acl_options' + tables.acl_roles: '%core.table_prefix%acl_roles' services: config.php: diff --git a/tests/di/fixtures/ext/vendor/enabled_4/environment.yml b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml index d0affe4fd6..d4ed5cbf24 100644 --- a/tests/di/fixtures/ext/vendor/enabled_4/environment.yml +++ b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml @@ -1,2 +1,4 @@ parameters: enabled_4: true + tables.foo_bar: '%core.table_prefix%foo_bar' + tables.acl_groups: '%core.table_prefix%some_other' diff --git a/tests/di/ordered_service_collection_test.php b/tests/di/ordered_service_collection_test.php index 47e6d23744..baa9776573 100644 --- a/tests/di/ordered_service_collection_test.php +++ b/tests/di/ordered_service_collection_test.php @@ -18,7 +18,7 @@ class phpbb_ordered_service_collection_test extends \phpbb_test_case */ protected $service_collection; - public function setUp() + public function setUp(): void { $container = new phpbb_mock_container_builder(); $container->set('foo', new StdClass); diff --git a/tests/di/service_collection_test.php b/tests/di/service_collection_test.php index 5b51254a4a..97c13ab163 100644 --- a/tests/di/service_collection_test.php +++ b/tests/di/service_collection_test.php @@ -18,15 +18,19 @@ class phpbb_service_collection_test extends \phpbb_test_case */ protected $service_collection; - public function setUp() + public function setUp(): void { $container = new phpbb_mock_container_builder(); $container->set('foo', new StdClass); $container->set('bar', new StdClass); + $container->set('baz', new StdClass); $this->service_collection = new \phpbb\di\service_collection($container); $this->service_collection->add('foo'); $this->service_collection->add('bar'); + $this->service_collection->add_service_class('foo', 'foo_class'); + $this->service_collection->add_service_class('bar', 'bar_class'); + $this->service_collection->add_service_class('baz', 'bar_class'); parent::setUp(); } @@ -44,4 +48,25 @@ class phpbb_service_collection_test extends \phpbb_test_case $this->assertSame(array('foo', 'bar'), $service_names); } + + public function test_get_by_class() + { + $this->assertSame($this->service_collection['foo'], $this->service_collection->get_by_class('foo_class')); + } + + public function test_get_by_class_many_services_exception() + { + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('More than one service definitions found for class "bar_class" in collection.'); + + $this->service_collection->get_by_class('bar_class'); + } + + public function test_get_by_class_no_service_exception() + { + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('No service found for class "baz_class" in collection.'); + + $this->service_collection->get_by_class('baz_class'); + } } |