|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheCodingMachine\Interop\ServiceProviderBridgeBundle; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
9
|
|
|
|
|
10
|
|
|
class SymfonyContainerAdapterTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
public function testContainer() |
|
14
|
|
|
{ |
|
15
|
|
|
$container = new ContainerBuilder(); |
|
16
|
|
|
$container->setParameter('database_host', 'localhost'); |
|
17
|
|
|
|
|
18
|
|
|
$container->compile(); |
|
19
|
|
|
|
|
20
|
|
|
$containerAdapter = new SymfonyContainerAdapter($container); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertTrue($containerAdapter->has('database_host')); |
|
23
|
|
|
$this->assertFalse($containerAdapter->has('not_exists')); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @expectedException \TheCodingMachine\Interop\ServiceProviderBridgeBundle\Exception\NotFoundException |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testContainerNotFound() |
|
30
|
|
|
{ |
|
31
|
|
|
$container = new ContainerBuilder(); |
|
32
|
|
|
$container->compile(); |
|
33
|
|
|
$containerAdapter = new SymfonyContainerAdapter($container); |
|
34
|
|
|
|
|
35
|
|
|
$containerAdapter->get('not_found'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @expectedException \TheCodingMachine\Interop\ServiceProviderBridgeBundle\Exception\ContainerException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testContainerWithException() |
|
42
|
|
|
{ |
|
43
|
|
|
$container = new ContainerBuilder(); |
|
44
|
|
|
$definition = new Definition(\stdClass::class); |
|
45
|
|
|
$definition->setFactory(self::class, "exceptionFactory"); |
|
|
|
|
|
|
46
|
|
|
$container->setDefinition('mydef', $definition); |
|
47
|
|
|
$container->compile(); |
|
48
|
|
|
$containerAdapter = new SymfonyContainerAdapter($container); |
|
49
|
|
|
|
|
50
|
|
|
$containerAdapter->get('mydef'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public static function exceptionFactory() |
|
54
|
|
|
{ |
|
55
|
|
|
throw new \Exception('Boom!'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
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
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.