1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dziki\MonologSentryBundle\Tests\Functional; |
6
|
|
|
|
7
|
|
|
use Dziki\MonologSentryBundle\DependencyInjection\MonologSentryExtension; |
8
|
|
|
use Dziki\MonologSentryBundle\Processor\TagAppending; |
9
|
|
|
use Dziki\MonologSentryBundle\SubscribedProcessor\BrowserDataAppending; |
10
|
|
|
use Dziki\MonologSentryBundle\SubscribedProcessor\UserDataAppending; |
11
|
|
|
use Dziki\MonologSentryBundle\UserAgent\CachedParser; |
12
|
|
|
use Dziki\MonologSentryBundle\UserAgent\NativeParser; |
13
|
|
|
use Dziki\MonologSentryBundle\UserAgent\PhpUserAgentParser; |
14
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
15
|
|
|
use Symfony\Component\Cache\Adapter\ArrayAdapter; |
16
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
17
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
18
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
19
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
20
|
|
|
|
21
|
|
|
class MonologSentryExtensionTest extends AbstractExtensionTestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
* @covers \Dziki\MonologSentryBundle\DependencyInjection\MonologSentryExtension::load |
26
|
|
|
* |
27
|
|
|
* @uses \Dziki\MonologSentryBundle\DependencyInjection\Configuration |
28
|
|
|
*/ |
29
|
|
|
public function checkIfServicesDefinedAndPrivate(): void |
30
|
|
|
{ |
31
|
|
|
$this->load( |
32
|
|
|
[ |
33
|
|
|
'user_context' => true, |
34
|
|
|
'user_agent_parser' => 'phpuseragent', |
35
|
|
|
'tags' => [ |
36
|
|
|
'test' => 'test', |
37
|
|
|
'test2' => [ |
38
|
|
|
'name' => 'test2', |
39
|
|
|
'value' => 'test2', |
40
|
|
|
], |
41
|
|
|
], |
42
|
|
|
] |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$defaultServices = [ |
46
|
|
|
'dziki.monolog_sentry_bundle.user_data_appending_subscribed_processor' => [ |
47
|
|
|
'class' => UserDataAppending::class, |
48
|
|
|
], |
49
|
|
|
PhpUserAgentParser::class => [ |
50
|
|
|
'class' => PhpUserAgentParser::class, |
51
|
|
|
], |
52
|
|
|
'dziki.monolog_sentry_bundle.browser_data_appending_subscribed_processor' => [ |
53
|
|
|
'class' => BrowserDataAppending::class, |
54
|
|
|
], |
55
|
|
|
'dziki.monolog_sentry_bundle.test_appending_processor' => [ |
56
|
|
|
'class' => TagAppending::class, |
57
|
|
|
], |
58
|
|
|
'dziki.monolog_sentry_bundle.test2_appending_processor' => [ |
59
|
|
|
'class' => TagAppending::class, |
60
|
|
|
], |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
$this->registerService(TokenStorageInterface::class, TokenStorage::class); |
64
|
|
|
$this->compile(); |
65
|
|
|
|
66
|
|
|
$this->assertServicesDefinedAndPrivate($defaultServices); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function assertServicesDefinedAndPrivate($defaultServices): void |
70
|
|
|
{ |
71
|
|
|
foreach ($defaultServices as $defaultService => $data) { |
72
|
|
|
$this->assertContainerBuilderHasService($defaultService, $data['class']); |
73
|
|
|
try { |
74
|
|
|
$service = $this->container->get($defaultService); |
75
|
|
|
|
76
|
|
|
if (Kernel::MAJOR_VERSION >= 4) { |
77
|
|
|
$this->fail(sprintf('Service "%s" (%s) should be private', \get_class($service), $defaultService)); |
78
|
|
|
} |
79
|
|
|
} catch (ServiceNotFoundException $exception) { |
80
|
|
|
$this->assertStringContainsString($defaultService, $exception->getMessage()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @test |
87
|
|
|
* @covers \Dziki\MonologSentryBundle\DependencyInjection\MonologSentryExtension::load |
88
|
|
|
* |
89
|
|
|
* @uses \Dziki\MonologSentryBundle\DependencyInjection\Configuration |
90
|
|
|
*/ |
91
|
|
|
public function checkIfNativeUserAgentParserServiceDefinedAndPrivate(): void |
92
|
|
|
{ |
93
|
|
|
if (!ini_get('browscap')) { |
94
|
|
|
$this->markTestSkipped( |
95
|
|
|
'The browscap.ini directive not set, skipped.' |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$this->load( |
100
|
|
|
[ |
101
|
|
|
'user_context' => false, |
102
|
|
|
'user_agent_parser' => 'native', |
103
|
|
|
] |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$defaultServices = [ |
107
|
|
|
NativeParser::class => [ |
108
|
|
|
'class' => NativeParser::class, |
109
|
|
|
], |
110
|
|
|
]; |
111
|
|
|
$this->compile(); |
112
|
|
|
|
113
|
|
|
$this->assertServicesDefinedAndPrivate($defaultServices); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @test |
118
|
|
|
* @covers \Dziki\MonologSentryBundle\DependencyInjection\MonologSentryExtension::load |
119
|
|
|
* |
120
|
|
|
* @uses \Dziki\MonologSentryBundle\DependencyInjection\Configuration |
121
|
|
|
*/ |
122
|
|
|
public function checkIfCachedParserServiceDefinedAndPrivate(): void |
123
|
|
|
{ |
124
|
|
|
$this->load( |
125
|
|
|
[ |
126
|
|
|
'user_context' => false, |
127
|
|
|
'user_agent_parser' => 'phpuseragent', |
128
|
|
|
'cache' => 'app.cache.simple', |
129
|
|
|
] |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$defaultServices = [ |
133
|
|
|
PhpUserAgentParser::class => [ |
134
|
|
|
'class' => PhpUserAgentParser::class, |
135
|
|
|
], |
136
|
|
|
CachedParser::class => [ |
137
|
|
|
'class' => CachedParser::class, |
138
|
|
|
], |
139
|
|
|
]; |
140
|
|
|
|
141
|
|
|
$this->registerService('app.cache.simple', ArrayAdapter::class); |
142
|
|
|
$this->compile(); |
143
|
|
|
|
144
|
|
|
$this->assertServicesDefinedAndPrivate($defaultServices); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
protected function getContainerExtensions(): array |
148
|
|
|
{ |
149
|
|
|
return [ |
150
|
|
|
new MonologSentryExtension(), |
151
|
|
|
]; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|