Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_service_collection_test | |
100.00% |
23 / 23 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_service_collection | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| test_get_by_class | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_by_class_many_services_exception | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_by_class_no_service_exception | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_service_collection_test extends \phpbb_test_case |
| 15 | { |
| 16 | /** |
| 17 | * @var \phpbb\di\service_collection |
| 18 | */ |
| 19 | protected $service_collection; |
| 20 | |
| 21 | protected function setUp(): void |
| 22 | { |
| 23 | $container = new phpbb_mock_container_builder(); |
| 24 | $container->set('foo', new StdClass); |
| 25 | $container->set('bar', new StdClass); |
| 26 | $container->set('baz', new StdClass); |
| 27 | |
| 28 | $this->service_collection = new \phpbb\di\service_collection($container); |
| 29 | $this->service_collection->add('foo'); |
| 30 | $this->service_collection->add('bar'); |
| 31 | $this->service_collection->add_service_class('foo', 'foo_class'); |
| 32 | $this->service_collection->add_service_class('bar', 'bar_class'); |
| 33 | $this->service_collection->add_service_class('baz', 'bar_class'); |
| 34 | |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function test_service_collection() |
| 39 | { |
| 40 | $service_names = array(); |
| 41 | |
| 42 | // Test the iterator |
| 43 | foreach ($this->service_collection as $name => $service) |
| 44 | { |
| 45 | $service_names[] = $name; |
| 46 | $this->assertInstanceOf('StdClass', $service); |
| 47 | } |
| 48 | |
| 49 | $this->assertSame(array('foo', 'bar'), $service_names); |
| 50 | } |
| 51 | |
| 52 | public function test_get_by_class() |
| 53 | { |
| 54 | $this->assertSame($this->service_collection['foo'], $this->service_collection->get_by_class('foo_class')); |
| 55 | } |
| 56 | |
| 57 | public function test_get_by_class_many_services_exception() |
| 58 | { |
| 59 | $this->expectException('RuntimeException'); |
| 60 | $this->expectExceptionMessage('DI_MULTIPLE_SERVICE_DEFINITIONS'); |
| 61 | |
| 62 | $this->service_collection->get_by_class('bar_class'); |
| 63 | } |
| 64 | |
| 65 | public function test_get_by_class_no_service_exception() |
| 66 | { |
| 67 | $this->expectException('RuntimeException'); |
| 68 | $this->expectExceptionMessage('DI_SERVICE_NOT_FOUND'); |
| 69 | |
| 70 | $this->service_collection->get_by_class('baz_class'); |
| 71 | } |
| 72 | } |