FailureActionListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 55.56%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 28
wmc 4
lcom 0
cbo 0
ccs 5
cts 9
cp 0.5556
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addFailure() 0 11 3
A getUniqueName() 0 4 1
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