aboutsummaryrefslogtreecommitdiffstats
path: root/tests/di/service_collection_test.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/di/service_collection_test.php')
-rw-r--r--tests/di/service_collection_test.php27
1 files changed, 26 insertions, 1 deletions
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');
+ }
}