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