1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Tests\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Liip\MonitorBundle\DependencyInjection\Compiler\AddGroupsCompilerPass; |
6
|
|
|
use Liip\MonitorBundle\DependencyInjection\Compiler\CheckCollectionTagCompilerPass; |
7
|
|
|
use Liip\MonitorBundle\DependencyInjection\Compiler\CheckTagCompilerPass; |
8
|
|
|
use Liip\MonitorBundle\DependencyInjection\Compiler\GroupRunnersCompilerPass; |
9
|
|
|
use Liip\MonitorBundle\DependencyInjection\LiipMonitorExtension; |
10
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Kevin Bond <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class LiipMonitorExtensionTest extends AbstractExtensionTestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @dataProvider checkProvider |
20
|
|
|
*/ |
21
|
|
|
public function testChecksLoaded($name, $config, $checkClass, $checkAlias = null, $checkCount = 1) |
22
|
|
|
{ |
23
|
|
|
// skip checks for missing classes |
24
|
|
|
if (!class_exists($checkClass)) { |
25
|
|
|
$this->setExpectedException('InvalidArgumentException'); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if (!$checkAlias) { |
29
|
|
|
$checkAlias = $name; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$this->load(array('checks' => array($name => $config))); |
33
|
|
|
$this->compile(); |
34
|
|
|
|
35
|
|
|
$runner = $this->container->get('liip_monitor.runner'); |
36
|
|
|
|
37
|
|
|
$this->assertCount($checkCount, $runner->getChecks()); |
38
|
|
|
$this->assertInstanceOf($checkClass, $runner->getCheck($checkAlias)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testDefaultNoChecks() |
42
|
|
|
{ |
43
|
|
|
$this->load(); |
44
|
|
|
$this->compile(); |
45
|
|
|
|
46
|
|
|
$this->assertCount(0, $this->container->get('liip_monitor.runner')->getChecks()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testDefaultGroupParameterHasNoChecks() |
50
|
|
|
{ |
51
|
|
|
$this->load(); |
52
|
|
|
$this->compile(); |
53
|
|
|
|
54
|
|
|
$this->assertTrue($this->container->hasParameter('liip_monitor.default_group')); |
55
|
|
|
$this->assertSame('default', $this->container->getParameter('liip_monitor.default_group')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testDefaultGroupParameter() |
59
|
|
|
{ |
60
|
|
|
$this->load(array('checks' => array('php_extensions' => array('foo')))); |
61
|
|
|
$this->compile(); |
62
|
|
|
|
63
|
|
|
$this->assertTrue($this->container->hasParameter('liip_monitor.default_group')); |
64
|
|
|
$this->assertSame('default', $this->container->getParameter('liip_monitor.default_group')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testDefaultGroupParameterCustom() |
68
|
|
|
{ |
69
|
|
|
$this->load(array('checks' => array('php_extensions' => array('foo')), 'default_group' => 'foo_bar')); |
70
|
|
|
$this->compile(); |
71
|
|
|
|
72
|
|
|
$this->assertTrue($this->container->hasParameter('liip_monitor.default_group')); |
73
|
|
|
$this->assertSame('foo_bar', $this->container->getParameter('liip_monitor.default_group')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testEnableController() |
77
|
|
|
{ |
78
|
|
|
$this->load(); |
79
|
|
|
|
80
|
|
|
$this->assertFalse($this->container->has('liip_monitor.health_controller')); |
81
|
|
|
|
82
|
|
|
$this->container->set('assets.packages', new Definition()); |
83
|
|
|
$this->load(array('enable_controller' => true)); |
84
|
|
|
|
85
|
|
|
$this->assertTrue($this->container->has('liip_monitor.health_controller')); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @expectedException Symfony\Component\DependencyInjection\Exception\LogicException |
90
|
|
|
*/ |
91
|
|
|
public function testEnableControllerFailsWithoutAssets() |
92
|
|
|
{ |
93
|
|
|
$this->load(array('enable_controller' => true)); |
94
|
|
|
|
95
|
|
|
$this->assertTrue($this->container->has('liip_monitor.health_controller')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testMailer() |
99
|
|
|
{ |
100
|
|
|
$this->load(); |
101
|
|
|
|
102
|
|
|
$this->assertEquals(false, $this->container->has('liip_monitor.reporter.swift_mailer')); |
103
|
|
|
|
104
|
|
|
$this->load( |
105
|
|
|
array( |
106
|
|
|
'mailer' => array( |
107
|
|
|
'recipient' => '[email protected]', |
108
|
|
|
'sender' => '[email protected]', |
109
|
|
|
'subject' => 'Health Check', |
110
|
|
|
'send_on_warning' => true, |
111
|
|
|
), |
112
|
|
|
) |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->assertContainerBuilderHasService('liip_monitor.reporter.swift_mailer'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @dataProvider mailerConfigProvider |
120
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
121
|
|
|
*/ |
122
|
|
|
public function testInvalidMailerConfig($config) |
123
|
|
|
{ |
124
|
|
|
$this->load($config); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function mailerConfigProvider() |
128
|
|
|
{ |
129
|
|
|
return array( |
130
|
|
|
array( |
131
|
|
|
array( |
132
|
|
|
'mailer' => array( |
133
|
|
|
'recipient' => '[email protected]', |
134
|
|
|
), |
135
|
|
|
), |
136
|
|
|
), |
137
|
|
|
array( |
138
|
|
|
array( |
139
|
|
|
'mailer' => array( |
140
|
|
|
'recipient' => '[email protected]', |
141
|
|
|
'sender' => '[email protected]', |
142
|
|
|
'subject' => null, |
143
|
|
|
), |
144
|
|
|
), |
145
|
|
|
), |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @dataProvider invalidCheckProvider |
151
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
152
|
|
|
*/ |
153
|
|
|
public function testInvalidExpressionConfig(array $config) |
154
|
|
|
{ |
155
|
|
|
$this->load(array('checks' => array('expressions' => $config))); |
156
|
|
|
$this->compile(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function invalidCheckProvider() |
160
|
|
|
{ |
161
|
|
|
return array( |
162
|
|
|
array(array('foo')), |
163
|
|
|
array(array('foo' => array('critical_expression' => 'true'))), |
164
|
|
|
array(array('foo' => array('label' => 'foo'))), |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function checkProvider() |
169
|
|
|
{ |
170
|
|
|
return array( |
171
|
|
|
array('php_extensions', array('foo'), 'ZendDiagnostics\Check\ExtensionLoaded'), |
172
|
|
|
array('php_flags', array('foo' => 'true'), 'ZendDiagnostics\Check\PhpFlag', 'php_flag_foo'), |
173
|
|
|
array('php_version', array('5.3.3' => '='), 'ZendDiagnostics\Check\PhpVersion', 'php_version_5.3.3'), |
174
|
|
|
array('process_running', 'foo', 'ZendDiagnostics\Check\ProcessRunning', 'process_foo_running'), |
175
|
|
|
array('process_running', array('foo'), 'ZendDiagnostics\Check\ProcessRunning', 'process_foo_running'), |
176
|
|
|
array('process_running', array('foo', 'bar'), 'ZendDiagnostics\Check\ProcessRunning', 'process_foo_running', 2), |
177
|
|
|
array('process_running', array('foo', 'bar'), 'ZendDiagnostics\Check\ProcessRunning', 'process_bar_running', 2), |
178
|
|
|
array('readable_directory', array('foo'), 'ZendDiagnostics\Check\DirReadable'), |
179
|
|
|
array('writable_directory', array('foo'), 'ZendDiagnostics\Check\DirWritable'), |
180
|
|
|
array('class_exists', array('Foo'), 'ZendDiagnostics\Check\ClassExists'), |
181
|
|
|
array('cpu_performance', 0.5, 'ZendDiagnostics\Check\CpuPerformance'), |
182
|
|
|
array('disk_usage', array('path' => __DIR__), 'ZendDiagnostics\Check\DiskUsage'), |
183
|
|
|
array('symfony_requirements', array('file' => __DIR__.'/../../LiipMonitorBundle.php'), 'Liip\MonitorBundle\Check\SymfonyRequirements'), |
184
|
|
|
array('opcache_memory', null, 'ZendDiagnostics\Check\OpCacheMemory'), |
185
|
|
|
array('apc_memory', null, 'ZendDiagnostics\Check\ApcMemory'), |
186
|
|
|
array('apc_fragmentation', null, 'ZendDiagnostics\Check\ApcFragmentation'), |
187
|
|
|
array('doctrine_dbal', 'foo', 'Liip\MonitorBundle\Check\DoctrineDbal', 'doctrine_dbal_foo_connection'), |
188
|
|
|
array('doctrine_dbal', array('foo'), 'Liip\MonitorBundle\Check\DoctrineDbal', 'doctrine_dbal_foo_connection'), |
189
|
|
|
array('doctrine_dbal', array('foo', 'bar'), 'Liip\MonitorBundle\Check\DoctrineDbal', 'doctrine_dbal_foo_connection', 2), |
190
|
|
|
array('doctrine_dbal', array('foo', 'bar'), 'Liip\MonitorBundle\Check\DoctrineDbal', 'doctrine_dbal_bar_connection', 2), |
191
|
|
|
array('memcache', array('foo' => null), 'ZendDiagnostics\Check\Memcache', 'memcache_foo'), |
192
|
|
|
array('redis', array('foo' => null), 'ZendDiagnostics\Check\Redis', 'redis_foo'), |
193
|
|
|
array('http_service', array('foo' => null), 'ZendDiagnostics\Check\HttpService', 'http_service_foo'), |
194
|
|
|
array('guzzle_http_service', array('foo' => null), 'ZendDiagnostics\Check\GuzzleHttpService', 'guzzle_http_service_foo'), |
195
|
|
|
array('rabbit_mq', array('foo' => null), 'ZendDiagnostics\Check\RabbitMQ', 'rabbit_mq_foo'), |
196
|
|
|
array('symfony_version', null, 'Liip\MonitorBundle\Check\SymfonyVersion'), |
197
|
|
|
array('custom_error_pages', array('error_codes' => array(500), 'path' => __DIR__, 'controller' => 'foo'), 'Liip\MonitorBundle\Check\CustomErrorPages'), |
198
|
|
|
array('security_advisory', array('lock_file' => __DIR__.'/../../composer.lock'), 'ZendDiagnostics\Check\SecurityAdvisory'), |
199
|
|
|
array('stream_wrapper_exists', array('foo'), 'ZendDiagnostics\Check\StreamWrapperExists'), |
200
|
|
|
array('file_ini', array('foo.ini'), 'ZendDiagnostics\Check\IniFile'), |
201
|
|
|
array('file_json', array('foo.json'), 'ZendDiagnostics\Check\JsonFile'), |
202
|
|
|
array('file_xml', array('foo.xml'), 'ZendDiagnostics\Check\XmlFile'), |
203
|
|
|
array('file_yaml', array('foo.yaml'), 'ZendDiagnostics\Check\YamlFile'), |
204
|
|
|
array('expressions', array('foo' => array('label' => 'foo', 'critical_expression' => 'true')), 'Liip\MonitorBundle\Check\Expression', 'expression_foo'), |
205
|
|
|
array('pdo_connections', array('foo' => array('dsn' => 'my-dsn')), 'ZendDiagnostics\Check\PDOCheck', 'pdo_foo'), |
206
|
|
|
); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
protected function getContainerExtensions() |
210
|
|
|
{ |
211
|
|
|
return array(new LiipMonitorExtension()); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
protected function compile() |
215
|
|
|
{ |
216
|
|
|
$doctrineMock = $this->getMockBuilder('Doctrine\Common\Persistence\ConnectionRegistry')->getMock(); |
217
|
|
|
$this->container->set('doctrine', $doctrineMock); |
218
|
|
|
$this->container->addCompilerPass(new AddGroupsCompilerPass()); |
219
|
|
|
$this->container->addCompilerPass(new GroupRunnersCompilerPass()); |
220
|
|
|
$this->container->addCompilerPass(new CheckTagCompilerPass()); |
221
|
|
|
$this->container->addCompilerPass(new CheckCollectionTagCompilerPass()); |
222
|
|
|
|
223
|
|
|
parent::compile(); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.