Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
62.50% |
15 / 24 |
|
42.86% |
6 / 14 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_mock_container_builder | |
62.50% |
15 / 24 |
|
42.86% |
6 / 14 |
38.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| set | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
5.93 | |||
| has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getParameter | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| hasParameter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setParameter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| enterScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| leaveScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasScope | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isScopeActive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isCompiled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| initialized | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | use Symfony\Component\DependencyInjection\ContainerInterface; |
| 14 | use Symfony\Component\DependencyInjection\ScopeInterface; |
| 15 | |
| 16 | class phpbb_mock_container_builder implements ContainerInterface |
| 17 | { |
| 18 | protected $services = array(); |
| 19 | protected $parameters = array(); |
| 20 | |
| 21 | public function __construct() |
| 22 | { |
| 23 | $this->setParameter('debug.load_time', false); |
| 24 | $this->setParameter('session.log_errors', false); |
| 25 | $this->setParameter('session.force_sid', true); |
| 26 | $this->setParameter('finder.cache', false); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Sets a service. |
| 31 | * |
| 32 | * @param string $id The service identifier |
| 33 | * @param object $service The service instance |
| 34 | * @param bool $shared Whether service is shared |
| 35 | * |
| 36 | * @api |
| 37 | */ |
| 38 | public function set(string $id, mixed $service): void |
| 39 | { |
| 40 | $this->services[$id] = $service; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Gets a service. |
| 45 | * |
| 46 | * @param string $id The service identifier |
| 47 | * @param int $invalidBehavior The behavior when the service does not exist |
| 48 | * |
| 49 | * @return object The associated service |
| 50 | * |
| 51 | * @throws InvalidArgumentException if the service is not defined |
| 52 | * @throws ServiceCircularReferenceException When a circular reference is detected |
| 53 | * @throws ServiceNotFoundException When the service is not defined |
| 54 | * |
| 55 | * @see Reference |
| 56 | * |
| 57 | * @api |
| 58 | */ |
| 59 | public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE): object|null |
| 60 | { |
| 61 | if ($this->has($id)) |
| 62 | { |
| 63 | $service = $this->services[$id]; |
| 64 | if (is_array($service) && isset($service[0]) && is_callable($service[0])) |
| 65 | { |
| 66 | return call_user_func_array($service[0], $service[1]); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | return $service; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | throw new Exception('Could not find service: ' . $id); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns true if the given service is defined. |
| 79 | * |
| 80 | * @param string $id The service identifier |
| 81 | * |
| 82 | * @return bool true if the service is defined, false otherwise |
| 83 | * |
| 84 | * @api |
| 85 | */ |
| 86 | public function has(string $id): bool |
| 87 | { |
| 88 | return isset($this->services[$id]); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets a parameter. |
| 93 | * |
| 94 | * @param string $name The parameter name |
| 95 | * |
| 96 | * @return mixed The parameter value |
| 97 | * |
| 98 | * @throws InvalidArgumentException if the parameter is not defined |
| 99 | * |
| 100 | * @api |
| 101 | */ |
| 102 | public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null |
| 103 | { |
| 104 | if ($this->hasParameter($name)) |
| 105 | { |
| 106 | return $this->parameters[$name]; |
| 107 | } |
| 108 | |
| 109 | throw new Exception('Could not find parameter: ' . $name); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Checks if a parameter exists. |
| 114 | * |
| 115 | * @param string $name The parameter name |
| 116 | * |
| 117 | * @return bool The presence of parameter in container |
| 118 | * |
| 119 | * @api |
| 120 | */ |
| 121 | public function hasParameter(string $name): bool |
| 122 | { |
| 123 | return isset($this->parameters[$name]); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Sets a parameter. |
| 128 | * |
| 129 | * @param string $name The parameter name |
| 130 | * @param mixed $value The parameter value |
| 131 | * |
| 132 | * @api |
| 133 | */ |
| 134 | public function setParameter($name, array|bool|string|int|float|\UnitEnum|null $value): void |
| 135 | { |
| 136 | $this->parameters[$name] = $value; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Enters the given scope |
| 141 | * |
| 142 | * @param string $name |
| 143 | * |
| 144 | * @api |
| 145 | */ |
| 146 | public function enterScope($name) |
| 147 | { |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Leaves the current scope, and re-enters the parent scope |
| 152 | * |
| 153 | * @param string $name |
| 154 | * |
| 155 | * @api |
| 156 | */ |
| 157 | public function leaveScope($name) |
| 158 | { |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Adds a scope to the container |
| 163 | * |
| 164 | * @param ScopeInterface $scope |
| 165 | * |
| 166 | * @api |
| 167 | */ |
| 168 | public function addScope(ScopeInterface $scope) |
| 169 | { |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Whether this container has the given scope |
| 174 | * |
| 175 | * @param string $name |
| 176 | * |
| 177 | * @return Boolean |
| 178 | * |
| 179 | * @api |
| 180 | */ |
| 181 | public function hasScope($name) |
| 182 | { |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Determines whether the given scope is currently active. |
| 187 | * |
| 188 | * It does however not check if the scope actually exists. |
| 189 | * |
| 190 | * @param string $name |
| 191 | * |
| 192 | * @return Boolean |
| 193 | * |
| 194 | * @api |
| 195 | */ |
| 196 | public function isScopeActive($name) |
| 197 | { |
| 198 | } |
| 199 | |
| 200 | public function isCompiled() |
| 201 | { |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | public function initialized($id): bool |
| 206 | { |
| 207 | return true; |
| 208 | } |
| 209 | } |