Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
70 / 70
100.00% covered (success)
100.00%
10 / 10
CRAP
100.00% covered (success)
100.00%
2 / 2
phpbb_di_create_container_test
100.00% covered (success)
100.00%
63 / 63
100.00% covered (success)
100.00%
8 / 8
9
100.00% covered (success)
100.00%
1 / 1
 setUp
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 test_default_container
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
1
 test_tables_mapping
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 test_without_cache
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 test_without_extensions
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 test_without_compiled_container
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 test_with_config_path
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 test_with_custom_parameters
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
manager_mock
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 all_enabled
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
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
14namespace
15{
16    require_once __DIR__ . '/fixtures/ext/vendor/enabled_4/di/extension.php';
17
18    class phpbb_di_create_container_test extends \phpbb_test_case
19    {
20        protected $config_php;
21
22        /**
23        * @var \phpbb\di\container_builder
24        */
25        protected $builder;
26        protected $phpbb_root_path;
27        protected $filename;
28
29        protected function setUp(): void
30        {
31            $this->phpbb_root_path = __DIR__ . '/';
32            $this->config_php = new \phpbb\config_php_file($this->phpbb_root_path . 'fixtures/', 'php');
33            $this->builder = new phpbb_mock_phpbb_di_container_builder($this->phpbb_root_path . 'fixtures/', 'php');
34            $this->builder->with_config($this->config_php);
35
36            $this->filename = $this->phpbb_root_path . '../tmp/container.php';
37            if (is_file($this->filename))
38            {
39                unlink($this->filename);
40            }
41
42            parent::setUp();
43        }
44
45        public function test_default_container()
46        {
47            $container = $this->builder->get_container();
48            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
49            $this->assertFalse($container->hasParameter('container_exception'));
50
51            // Checks the core services
52            $this->assertTrue($container->hasParameter('core'));
53
54            // Checks compile_container
55            $this->assertTrue($container->isCompiled());
56
57            // Checks inject_config
58            $this->assertTrue($container->hasParameter('core.table_prefix'));
59
60            // Checks use_extensions
61            $this->assertTrue($container->hasParameter('enabled'));
62            $this->assertTrue($container->hasParameter('enabled_2'));
63            $this->assertTrue($container->hasParameter('enabled_3'));
64            $this->assertTrue($container->hasParameter('enabled_4'));
65            $this->assertFalse($container->hasParameter('disabled'));
66            $this->assertFalse($container->hasParameter('available'));
67
68            // Checks set_custom_parameters
69            $this->assertTrue($container->hasParameter('core.root_path'));
70
71            // Checks dump_container
72            $this->assertTrue(is_file($this->filename));
73
74            // Checks the construction of a dumped container
75            $container = $this->builder->get_container();
76            $this->assertEquals('phpbb_cache_container', $container::class);
77            $this->assertInstanceOf('Symfony\Component\DependencyInjection\Container', $container);
78            $this->assertTrue($container->isCompiled());
79        }
80
81        public function test_tables_mapping()
82        {
83            $this->builder->without_cache();
84            $container = $this->builder->get_container();
85            $this->assertTrue($container->hasParameter('tables'));
86            $tables = $container->getParameter('tables');
87            $this->assertGreaterThan(0, count($tables));
88            $this->assertTrue($container->hasParameter('tables.foo_bar'));
89            $this->assertTrue(isset($tables['foo_bar']));
90            $this->assertEquals($tables['acl_groups'], 'phpbb_some_other');
91        }
92
93        public function test_without_cache()
94        {
95            $this->builder->without_cache();
96            $container = $this->builder->get_container();
97            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
98
99            // Checks dump_container
100            $this->assertFalse(is_file($this->filename));
101
102            // Checks the construction of a dumped container
103            $container = $this->builder->get_container();
104            $this->assertNotEquals('phpbb_cache_container', $container::class);
105            $this->assertEquals('Symfony\Component\DependencyInjection\ContainerBuilder', $container::class);
106            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
107            $this->assertTrue($container->isCompiled());
108        }
109
110        public function test_without_extensions()
111        {
112            $this->builder->without_extensions();
113            $container = $this->builder->get_container();
114            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
115
116            // Checks the core services
117            $this->assertTrue($container->hasParameter('core'));
118
119            // Checks use_extensions
120            $this->assertFalse($container->hasParameter('enabled'));
121            $this->assertFalse($container->hasParameter('disabled'));
122            $this->assertFalse($container->hasParameter('available'));
123        }
124
125        public function test_without_compiled_container()
126        {
127            $this->builder->without_compiled_container();
128            $container = $this->builder->get_container();
129            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
130
131            // Checks compile_container
132            $this->assertFalse($container->isCompiled());
133        }
134
135        public function test_with_config_path()
136        {
137            $this->builder->with_config_path($this->phpbb_root_path . 'fixtures/other_config/');
138            $container = $this->builder->get_container();
139            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
140
141            $this->assertTrue($container->hasParameter('other_config'));
142            $this->assertFalse($container->hasParameter('core'));
143        }
144
145        public function test_with_custom_parameters()
146        {
147            $this->builder->with_custom_parameters(array('my_parameter' => true));
148            $container = $this->builder->get_container();
149            $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
150
151            $this->assertTrue($container->hasParameter('my_parameter'));
152        }
153    }
154}
155
156namespace phpbb\extension
157{
158    class manager_mock extends \phpbb\extension\manager
159    {
160        public function __construct()
161        {
162        }
163
164        public function all_enabled($phpbb_relative = true)
165        {
166            return array(
167                'vendor/enabled' => __DIR__ . '/fixtures/ext/vendor/enabled/',
168                'vendor/enabled-2' => __DIR__ . '/fixtures/ext/vendor/enabled-2/',
169                'vendor/enabled-3' => __DIR__ . '/fixtures/ext/vendor/enabled-3/',
170                'vendor/enabled_4' => __DIR__ . '/fixtures/ext/vendor/enabled_4/',
171            );
172        }
173    }
174}