-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathContainerTest.php
137 lines (115 loc) · 5.24 KB
/
ContainerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
declare(strict_types=1);
namespace Doctrine\Bundle\MongoDBBundle\Tests;
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use function sys_get_temp_dir;
class ContainerTest extends TestCase
{
private ContainerBuilder $container;
private DoctrineMongoDBExtension $extension;
protected function setUp(): void
{
$this->container = new ContainerBuilder(new ParameterBag([
'kernel.bundles' => [],
'kernel.cache_dir' => sys_get_temp_dir(),
'kernel.root_dir' => sys_get_temp_dir(),
'kernel.project_dir' => sys_get_temp_dir(),
'kernel.environment' => 'test',
'kernel.name' => 'kernel',
'kernel.debug' => true,
'kernel.container_class' => Container::class,
]));
$this->extension = new DoctrineMongoDBExtension();
}
/** @dataProvider provideLoggerConfigs */
public function testLoggerConfig(bool $expected, array $config, bool $debug): void
{
$this->container->setParameter('kernel.debug', $debug);
$this->extension->load([$config], $this->container);
$definition = $this->container->getDefinition('doctrine_mongodb.odm.psr_command_logger');
$this->assertSame($expected, $definition->hasTag('doctrine_mongodb.odm.command_logger'));
$this->container->compile();
// Fetch the command logger registry to make sure the appropriate number of services has been registered
$this->container->get('doctrine_mongodb.odm.command_logger_registry');
}
/** @return array<string, array{expected: bool, config: array, debug: bool}> */
public static function provideLoggerConfigs(): array
{
$config = ['connections' => ['default' => []]];
return [
'Debug mode enabled' => [
// Logging is always enabled in debug mode
'expected' => true,
'config' => [
'document_managers' => ['default' => []],
] + $config,
'debug' => true,
],
'Debug mode disabled' => [
// Logging is disabled by default when not in debug mode
'expected' => false,
'config' => [
'document_managers' => ['default' => []],
] + $config,
'debug' => false,
],
'Logging enabled by config' => [
// Logging can be enabled by config
'expected' => true,
'config' => [
'document_managers' => ['default' => ['logging' => true]],
] + $config,
'debug' => false,
],
];
}
/** @dataProvider provideDataCollectorConfigs */
public function testDataCollectorConfig(bool $expected, array $config, bool $debug): void
{
$this->container->setParameter('kernel.debug', $debug);
$this->extension->load([$config], $this->container);
$loggerDefinition = $this->container->getDefinition('doctrine_mongodb.odm.data_collector.command_logger');
$this->assertSame($expected, $loggerDefinition->hasTag('doctrine_mongodb.odm.command_logger'));
$stopwatchLoggerDefinition = $this->container->getDefinition('doctrine_mongodb.odm.stopwatch_command_logger');
$this->assertSame($expected, $stopwatchLoggerDefinition->hasTag('doctrine_mongodb.odm.command_logger'));
$dataCollectorDefinition = $this->container->getDefinition('doctrine_mongodb.odm.data_collector');
$this->assertSame($expected, $dataCollectorDefinition->hasTag('data_collector'));
$this->container->compile();
// Fetch the command logger registry to make sure the appropriate number of services has been registered
$this->container->get('doctrine_mongodb.odm.command_logger_registry');
}
/** @return array<string, array{expected: bool, config: array, debug: bool}> */
public static function provideDataCollectorConfigs(): array
{
$config = ['connections' => ['default' => []]];
return [
'Debug mode enabled' => [
// Profiling is always enabled in debug mode
'expected' => true,
'config' => [
'document_managers' => ['default' => []],
] + $config,
'debug' => true,
],
'Debug mode disabled' => [
// Profiling is disabled by default when not in debug mode
'expected' => false,
'config' => [
'document_managers' => ['default' => []],
] + $config,
'debug' => false,
],
'Profiling enabled by config' => [
// Profiling can be enabled by config
'expected' => true,
'config' => [
'document_managers' => ['default' => ['profiler' => true]],
] + $config,
'debug' => false,
],
];
}
}