AlertControllerTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testDisplayAlerts() 0 25 1
1
<?php
2
/**
3
 * AlertControllerTest.php
4
 * Definition of class AlertControllerTest
5
 *
6
 * Created 31/08/14 10:30
7
 *
8
 * @author Rasanga Perera <[email protected]>
9
 * Copyright (c) 2014, The MIT License (MIT)
10
 */
11
12
namespace Ras\Bundle\FlashAlertBundle\Tests\Controller;
13
14
15
use Ras\Bundle\FlashAlertBundle\Model\AlertReporter;
16
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
17
use Symfony\Component\HttpFoundation\Response;
18
19
class AlertControllerTest extends WebTestCase
20
{
21
22
    /**
23
     * @test
24
     * @covers \Ras\Bundle\FlashAlertBundle\Controller\AlertController::displayAlertsAction
25
     */
26
    public function testDisplayAlerts()
27
    {
28
        $client = static::createClient();
29
        $client->request('GET', '/ras_flash_alert/display_alerts');
30
31
        $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
32
33
        $client = static::createClient();
34
        /** @var AlertReporter $alertReporter */
35
        $alertReporter = $client->getContainer()->get('ras_flash_alert.alert_reporter');
36
        $alertMessage = "Test error flash alert";
37
        $alertReporter->addError($alertMessage);
38
39
        $crawler1 = $client->request('GET', '/ras_flash_alert/display_alerts');
40
41
        print_r($client->getResponse()->getContent());
42
43
        // Test: flash alert that has been added recently
44
        $this->assertTrue($crawler1->filter("html:contains(\"{$alertMessage}\")")->count() === 1);
45
46
        $crawler2 = $client->request('GET', '/ras_flash_alert/display_alerts');
47
48
        // Test: flash alert has already been retrieved
49
        $this->assertTrue($crawler2->filter("html:contains(\"{$alertMessage}\")")->count() === 0);
50
    }
51
52
}
53