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
|
|
|
class MonologHandlerOverridePassTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @test |
18
|
|
|
*/ |
19
|
|
|
public function doNothingIfNoRavenHandlerServiceDefined(): void |
20
|
|
|
{ |
21
|
|
|
$containerBuilder = new ContainerBuilder(); |
22
|
|
|
$expected = spl_object_hash($containerBuilder); |
23
|
|
|
|
24
|
|
|
$monologOverridePass = new MonologHandlerOverridePass(); |
25
|
|
|
$monologOverridePass->process($containerBuilder); |
26
|
|
|
|
27
|
|
|
self::assertEquals($expected, spl_object_hash($containerBuilder)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
|
public function changeClassDefinitionForAllAndOnlyRavenHandlerServices() |
34
|
|
|
{ |
35
|
|
|
$containerBuilder = new ContainerBuilder(); |
36
|
|
|
$containerBuilder->addDefinitions( |
37
|
|
|
[ |
38
|
|
|
'1' => new Definition(RavenHandler::class), |
39
|
|
|
'2' => new Definition(RavenHandler::class), |
40
|
|
|
'3' => new Definition(\stdClass::class), |
41
|
|
|
] |
42
|
|
|
); |
43
|
|
|
$oldClasses = []; |
44
|
|
|
foreach ($containerBuilder->getDefinitions() as $id => $definition) { |
45
|
|
|
$oldClasses[$id] = $definition->getClass(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$monologOverridePass = new MonologHandlerOverridePass(); |
49
|
|
|
$monologOverridePass->process($containerBuilder); |
50
|
|
|
|
51
|
|
|
foreach ($oldClasses as $id => $class) { |
52
|
|
|
if ($class === RavenHandler::class) { |
53
|
|
|
$this->assertSame( |
54
|
|
|
Raven::class, |
55
|
|
|
$containerBuilder |
56
|
|
|
->getDefinition($id) |
57
|
|
|
->getClass() |
58
|
|
|
); |
59
|
|
|
} else { |
60
|
|
|
$this->assertSame( |
61
|
|
|
$class, |
62
|
|
|
$containerBuilder |
63
|
|
|
->getDefinition($id) |
64
|
|
|
->getClass() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|