From deb556fbf05eeec447234f15f4eada58526f0b81 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 4 Jul 2017 16:39:18 +0200 Subject: [ticket/15258] Adds a method to get a service by class in service_collection PHPBB3-15258 --- tests/di/service_collection_test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/di/service_collection_test.php') diff --git a/tests/di/service_collection_test.php b/tests/di/service_collection_test.php index 5b51254a4a..5815b4367d 100644 --- a/tests/di/service_collection_test.php +++ b/tests/di/service_collection_test.php @@ -23,10 +23,14 @@ class phpbb_service_collection_test extends \phpbb_test_case $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,23 @@ 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->setExpectedException('RuntimeException', '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->setExpectedException('RuntimeException', 'No service found for class "baz_class" in collection.'); + + $this->service_collection->get_by_class('baz_class'); + } } -- cgit v1.2.1 From ebac54aa9e705e99a562d2fe2c0f57bc6af8dd32 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 30 Dec 2018 11:36:08 +0100 Subject: [ticket/14948] Adjust calls for twig and phpunit updates PHPBB3-14948 --- tests/di/service_collection_test.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/di/service_collection_test.php') diff --git a/tests/di/service_collection_test.php b/tests/di/service_collection_test.php index 5815b4367d..97c13ab163 100644 --- a/tests/di/service_collection_test.php +++ b/tests/di/service_collection_test.php @@ -18,7 +18,7 @@ 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); @@ -56,14 +56,16 @@ class phpbb_service_collection_test extends \phpbb_test_case public function test_get_by_class_many_services_exception() { - $this->setExpectedException('RuntimeException', 'More than one service definitions found for class "bar_class" in collection.'); + $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->setExpectedException('RuntimeException', 'No service found for class "baz_class" in collection.'); + $this->expectException('RuntimeException'); + $this->expectExceptionMessage('No service found for class "baz_class" in collection.'); $this->service_collection->get_by_class('baz_class'); } -- cgit v1.2.1