FailureActionListener::addFailure()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 3
cts 6
cp 0.5
rs 9.4285
cc 3
eloc 7
nc 3
nop 3
crap 4.125
1
<?php
2
3
namespace SP\Phpunit;
4
5
use PHPUnit_Framework_BaseTestListener;
6
use PHPUnit_Framework_Test;
7
use PHPUnit_Framework_AssertionFailedError;
8
9
/**
10
 * @author    Ivan Kerin <[email protected]>
11
 * @copyright 2016, Clippings Ltd.
12
 * @license   http://spdx.org/licenses/BSD-3-Clause
13
 */
14
class FailureActionListener extends PHPUnit_Framework_BaseTestListener
15
{
16
    /**
17
     * @param PHPUnit_Framework_Test                 $test
18
     * @param PHPUnit_Framework_AssertionFailedError $eception
19
     * @param string                                 $time
20
     */
21 1
    public function addFailure(
22
        PHPUnit_Framework_Test $test,
23
        PHPUnit_Framework_AssertionFailedError $eception,
24
        $time
25
    ) {
26 1
        if ($test instanceof FailureActionInterface) {
27 1
            foreach ($test->getFailureActions() as $callback) {
28
                call_user_func($callback, $this->getUniqueName($test));
29
            }
30
        }
31
    }
32
33
    /**
34
     * @param  PHPUnit_Framework_Test $test
35
     * @return string
36
     */
37 1
    public function getUniqueName(PHPUnit_Framework_Test $test)
38
    {
39
        return str_replace('\\', '_', get_class($test)).'::'.$test->getName();
40 1
    }
41
}
42