|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2017 Gerrit Addiks. |
|
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
|
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
|
7
|
|
|
* @license GPL-3.0 |
|
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Addiks\SymfonyGenerics\Tests\Unit\DependencyInjection\Compiler; |
|
12
|
|
|
|
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use Addiks\SymfonyGenerics\DependencyInjection\Compiler\ControllerErrorHandlingPass; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
17
|
|
|
use InvalidArgumentException; |
|
18
|
|
|
|
|
19
|
|
|
final class ControllerErrorHandlingPassTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @test |
|
24
|
|
|
*/ |
|
25
|
|
|
public function shouldProcessErrorHandlingServiceDefinition() |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var Definition $errorHandlerDefinition */ |
|
28
|
|
|
$errorHandlerDefinition = $this->createMock(Definition::class); |
|
29
|
|
|
$errorHandlerDefinition->expects($this->once())->method('addTag')->with( |
|
|
|
|
|
|
30
|
|
|
$this->equalTo('symfony_generics.decorates'), |
|
31
|
|
|
$this->equalTo(['abc' => 'def', 'foo' => 'bar', 'decorates' => 'some-controller-id']) |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
/** @var ContainerBuilder $container */ |
|
35
|
|
|
$container = $this->createMock(ContainerBuilder::class); |
|
36
|
|
|
$container->expects($this->exactly(2))->method('findTaggedServiceIds')->will($this->returnValueMap([ |
|
|
|
|
|
|
37
|
|
|
[ |
|
38
|
|
|
'symfony_generics.error_handler', |
|
39
|
|
|
false, |
|
40
|
|
|
['some-errorhandler-id' => [['key' => 'some-key', 'abc' => 'def']]], |
|
41
|
|
|
], |
|
42
|
|
|
[ |
|
43
|
|
|
'symfony_generics.error_handler.some-key', |
|
44
|
|
|
false, |
|
45
|
|
|
['some-controller-id' => [['foo' => 'bar']]], |
|
46
|
|
|
] |
|
47
|
|
|
])); |
|
48
|
|
|
$container->expects($this->once())->method('getDefinition')->with( |
|
|
|
|
|
|
49
|
|
|
$this->equalTo('some-errorhandler-id') |
|
50
|
|
|
)->willReturn($errorHandlerDefinition); |
|
51
|
|
|
|
|
52
|
|
|
$compilerPass = new ControllerErrorHandlingPass(); |
|
53
|
|
|
$compilerPass->process($container); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @test |
|
58
|
|
|
*/ |
|
59
|
|
|
public function shouldRejectErrorHandlerWithoutKey() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
62
|
|
|
|
|
63
|
|
|
/** @var ContainerBuilder $container */ |
|
64
|
|
|
$container = $this->createMock(ContainerBuilder::class); |
|
65
|
|
|
$container->expects($this->once())->method('findTaggedServiceIds')->will($this->returnValueMap([ |
|
|
|
|
|
|
66
|
|
|
[ |
|
67
|
|
|
'symfony_generics.error_handler', |
|
68
|
|
|
false, |
|
69
|
|
|
['some-errorhandler-id' => [['abc' => 'def']]], |
|
70
|
|
|
], |
|
71
|
|
|
])); |
|
72
|
|
|
|
|
73
|
|
|
$compilerPass = new ControllerErrorHandlingPass(); |
|
74
|
|
|
$compilerPass->process($container); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.