1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Go! AOP framework |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Go\Symfony\GoAopBundle\Tests\DependencyInjection\Compiler; |
12
|
|
|
|
13
|
|
|
use Go\Symfony\GoAopBundle\DependencyInjection\Compiler\AspectCollectorPass; |
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class AspectCollectorPassTest |
21
|
|
|
*/ |
22
|
|
|
class AspectCollectorPassTest extends AbstractCompilerPassTestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @test |
26
|
|
|
*/ |
27
|
|
|
public function itRegistersAspects() |
28
|
|
|
{ |
29
|
|
|
$this->setDefinition('goaop.aspect.container', new Definition()); |
30
|
|
|
|
31
|
|
|
$someAspect = new Definition(); |
32
|
|
|
$someAspect->addTag('goaop.aspect'); |
33
|
|
|
$this->setDefinition('some_aspect', $someAspect); |
34
|
|
|
|
35
|
|
|
$someOtherAspect = new Definition(); |
36
|
|
|
$someOtherAspect->addTag('goaop.aspect'); |
37
|
|
|
$this->setDefinition('some_other_aspect', $someOtherAspect); |
38
|
|
|
|
39
|
|
|
$this->compile(); |
40
|
|
|
|
41
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall('goaop.aspect.container', 'registerAspect', [new Reference('some_aspect')], 0); |
|
|
|
|
42
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall('goaop.aspect.container', 'registerAspect', [new Reference('some_other_aspect')], 1); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
49
|
|
|
{ |
50
|
|
|
$container->addCompilerPass(new AspectCollectorPass()); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.