Completed
Push — master ( a88ebf...a6f5e7 )
by John
02:15
created

TestCacheSmashingPHPUnitListener::addFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\JwtBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\JwtBundle\Tests\Functional;
10
11
use PHPUnit_Framework_Test;
12
use PHPUnit_Framework_AssertionFailedError;
13
use Exception;
14
use PHPUnit_Framework_TestSuite;
15
16
class TestCacheSmashingPHPUnitListener implements \PHPUnit_Framework_TestListener
17
{
18
    const SUITE_NAME = 'Functional';
19
20
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
21
    {
22
        //NOOP
23
    }
24
25
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
26
    {
27
        //NOOP
28
    }
29
30
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
31
    {
32
        //NOOP
33
    }
34
35
    public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
36
    {
37
        //NOOP
38
    }
39
40
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
41
    {
42
        //NOOP
43
    }
44
45
    public function startTest(PHPUnit_Framework_Test $test)
46
    {
47
        //NOOP
48
    }
49
50
    public function endTest(PHPUnit_Framework_Test $test, $time)
51
    {
52
        //NOOP
53
    }
54
55
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
56
    {
57
        $this->smashIfFunctionalSuite($suite);
58
    }
59
60
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
61
    {
62
        $this->smashIfFunctionalSuite($suite);
63
    }
64
65
    private function smashIfFunctionalSuite(PHPUnit_Framework_TestSuite $suite)
66
    {
67
        if ($suite->getName() !== self::SUITE_NAME) {
68
            return;
69
        }
70
71
        $dir = __DIR__ . '/App/app/cache';
72
73
        if (!is_dir($dir)) {
74
            return;
75
        }
76
77
        $iterator = new \RecursiveIteratorIterator(
78
            new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS),
79
            \RecursiveIteratorIterator::CHILD_FIRST
80
        );
81
82
        foreach ($iterator as $path) {
83
            $path->isDir() && !$path->isLink() ? rmdir($path->getPathname()) : unlink($path->getPathname());
84
        }
85
    }
86
}