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