1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dziki\MonologSentryBundle\Tests\Unit\DependencyInjection\Compiler; |
6
|
|
|
|
7
|
|
|
use Dziki\MonologSentryBundle\DependencyInjection\Compiler\MonologHandlerOverridePass; |
8
|
|
|
use Dziki\MonologSentryBundle\Handler\Raven; |
9
|
|
|
use Monolog\Handler\RavenHandler; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
12
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \Dziki\MonologSentryBundle\DependencyInjection\Compiler\MonologHandlerOverridePass |
16
|
|
|
*/ |
17
|
|
|
class MonologHandlerOverridePassTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
*/ |
22
|
|
|
public function doNothingIfNoRavenHandlerServiceDefined(): void |
23
|
|
|
{ |
24
|
|
|
$containerBuilder = new ContainerBuilder(); |
25
|
|
|
$expected = \spl_object_hash($containerBuilder); |
26
|
|
|
|
27
|
|
|
$monologOverridePass = new MonologHandlerOverridePass(); |
28
|
|
|
$monologOverridePass->process($containerBuilder); |
29
|
|
|
|
30
|
|
|
self::assertEquals($expected, \spl_object_hash($containerBuilder)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function changeClassDefinitionForAllAndOnlyRavenHandlerServices() |
37
|
|
|
{ |
38
|
|
|
$containerBuilder = new ContainerBuilder(); |
39
|
|
|
$containerBuilder->addDefinitions( |
40
|
|
|
[ |
41
|
|
|
'1' => new Definition(RavenHandler::class), |
42
|
|
|
'2' => new Definition(RavenHandler::class), |
43
|
|
|
'3' => new Definition(\stdClass::class), |
44
|
|
|
] |
45
|
|
|
); |
46
|
|
|
$oldClasses = []; |
47
|
|
|
foreach ($containerBuilder->getDefinitions() as $id => $definition) { |
48
|
|
|
$oldClasses[$id] = $definition->getClass(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$monologOverridePass = new MonologHandlerOverridePass(); |
52
|
|
|
$monologOverridePass->process($containerBuilder); |
53
|
|
|
|
54
|
|
|
foreach ($oldClasses as $id => $class) { |
55
|
|
|
if (RavenHandler::class === $class) { |
56
|
|
|
$this->assertSame( |
57
|
|
|
Raven::class, |
58
|
|
|
$containerBuilder |
59
|
|
|
->getDefinition((string) $id) |
60
|
|
|
->getClass() |
61
|
|
|
); |
62
|
|
|
} else { |
63
|
|
|
$this->assertSame( |
64
|
|
|
$class, |
65
|
|
|
$containerBuilder |
66
|
|
|
->getDefinition((string) $id) |
67
|
|
|
->getClass() |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|