Skip to content

Commit d0da9fd

Browse files
committed
add Tests, update Readme
1 parent fe4a567 commit d0da9fd

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

EventListener/MaintenanceListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public function onKernelRequest(GetResponseEvent $event)
5050
/**
5151
* Conditions : Maintenance enable, not in dev/test mode, not in enable Ips
5252
*/
53-
if ($this->enable && !in_array($this->kernel->getEnvironment(), ['test', 'dev']) && !in_array(@$_SERVER['REMOTE_ADDR'], $this->ips)) {
53+
if ($this->enable && !in_array($this->kernel->getEnvironment(), ['dev']) && !in_array(@$_SERVER['REMOTE_ADDR'], $this->ips)) {
5454
$content = $this->templating->render('@ArtgrisMaintenance/maintenance.html.twig');
55-
$event->setResponse(new Response($content, 503));
55+
$event->setResponse(new Response($content, Response::HTTP_SERVICE_UNAVAILABLE));
5656
$event->stopPropagation();
5757
}
5858
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Create your own twig in `app/Resources/ArtgrisMaintenanceBundle/view/maintenance
4646
Usage
4747
=====
4848

49-
The `dev` and `test` environments were not affected by maintenance.
49+
The `dev` environment was not affected by maintenance.
5050

5151
- Enable|Disable maintenance : `enable: true|false`
5252
- Add authorized IPs to prod : `ips: [127.0.0.1, ...]`

Tests/MaintenanceTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
namespace Artgris\MaintenanceBundle\Tests;
5+
6+
7+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
/**
11+
* Maintenance Test
12+
*
13+
* @author Arthur Gribet <[email protected]>
14+
*/
15+
class MaintenanceTest extends WebTestCase
16+
{
17+
public function testMaintenance()
18+
{
19+
$client = static::createClient();
20+
$client->request('GET', '/');
21+
static::assertEquals(
22+
Response::HTTP_SERVICE_UNAVAILABLE,
23+
$client->getResponse()->getStatusCode());
24+
}
25+
26+
}

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"symfony/framework-bundle": "^2.3 || ^3.0",
2121
"twig/twig": "~1.12"
2222
},
23+
"require-dev": {
24+
"phpunit/phpunit": "~3.7"
25+
},
2326
"autoload": {
2427
"psr-0": {
2528
"Artgris\\MaintenanceBundle": ""

0 commit comments

Comments
 (0)