aboutsummaryrefslogtreecommitdiffstats
path: root/tests/di/service_collection_test.php
diff options
context:
space:
mode:
authorMaat <maat-pub@mageia.biz>2020-05-09 01:15:08 +0200
committerMaat <maat-pub@mageia.biz>2020-05-09 01:15:08 +0200
commit6985226b17e8a0ef0a720bf1d12fe0c216e13dab (patch)
tree116d2565ac02c40abe0548863c6badf8ec3e1d1e /tests/di/service_collection_test.php
parent8ea437e30605e0f66b5220bf904a61d7c1d11ddd (diff)
parent8d00784dfe2c8bcb10843ff70b4cfa998d703285 (diff)
downloadforums-master.tar
forums-master.tar.gz
forums-master.tar.bz2
forums-master.tar.xz
forums-master.zip
Merge remote-tracking branch 'upstream/prep-release-3.3.0'HEADmaster
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');
+ }
}