|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Tests\DependencyInjection; |
|
5
|
|
|
|
|
6
|
|
|
use FH\Bundle\UserAgentBundle\DependencyInjection\FHUserAgentExtension; |
|
7
|
|
|
use FH\Bundle\UserAgentBundle\EventListener\ResponseListener; |
|
8
|
|
|
use FH\Bundle\UserAgentBundle\Repository\UserAgentRepository; |
|
9
|
|
|
use FH\Bundle\UserAgentBundle\Repository\UserAgentRepositoryInterface; |
|
10
|
|
|
use PHPUnit\Framework\Assert; |
|
|
|
|
|
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Evert Harmeling <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
final class FHUserAgentExtensionTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
private $container; |
|
20
|
|
|
private $extension; |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->container = new ContainerBuilder(); |
|
25
|
|
|
$this->extension = new FHUserAgentExtension(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function tearDown() |
|
29
|
|
|
{ |
|
30
|
|
|
unset($this->container, $this->extension); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testExtensionLoadedDefaults(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->extension->load([], $this->container); |
|
36
|
|
|
|
|
37
|
|
|
Assert::assertEquals(UserAgentRepository::class, $this->container->getAlias(UserAgentRepositoryInterface::class)); |
|
38
|
|
|
Assert::assertContains(ResponseListener::class, $this->container->getServiceIds()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testConfigRepository(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$customRepositoryService = 'fh_app.repository.user_agent'; |
|
44
|
|
|
|
|
45
|
|
|
$this->extension->load([ |
|
46
|
|
|
'fh_user_agent' => [ |
|
47
|
|
|
'repository' => $customRepositoryService |
|
48
|
|
|
] |
|
49
|
|
|
], $this->container); |
|
50
|
|
|
|
|
51
|
|
|
Assert::assertEquals($customRepositoryService, $this->container->getAlias(UserAgentRepositoryInterface::class)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testResponseListenerClass(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$customResponseListenerClass = 'fh_app.response_listener.class'; |
|
57
|
|
|
|
|
58
|
|
|
$this->extension->load([ |
|
59
|
|
|
'fh_user_agent' => [ |
|
60
|
|
|
'response_listener' => [ |
|
61
|
|
|
'class' => $customResponseListenerClass |
|
62
|
|
|
] |
|
63
|
|
|
] |
|
64
|
|
|
], $this->container); |
|
65
|
|
|
|
|
66
|
|
|
Assert::assertContains($customResponseListenerClass, $this->container->getServiceIds()); |
|
67
|
|
|
Assert::assertNotContains(ResponseListener::class, $this->container->getServiceIds()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testResponseListenerCriteria(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$host = 'api.domain.tld'; |
|
73
|
|
|
|
|
74
|
|
|
$this->extension->load([ |
|
75
|
|
|
'fh_user_agent' => [ |
|
76
|
|
|
'response_listener' => [ |
|
77
|
|
|
'criteria' => [ |
|
78
|
|
|
'host' => $host |
|
79
|
|
|
] |
|
80
|
|
|
] |
|
81
|
|
|
] |
|
82
|
|
|
], $this->container); |
|
83
|
|
|
|
|
84
|
|
|
Assert::assertTrue(true); // otherwise should throw exception, and internal property isn't testable |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths