FailureActionListener::getUniqueName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1.037
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