Completed
Pull Request — master (#99)
by Kevin
06:07
created

MasterListener::addIncompleteTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
c 3
b 2
f 1
dl 0
loc 8
rs 9.4285
nc 1
cc 1
eloc 5
nop 3
1
<?php
2
3
namespace Magium\Util\Phpunit;
4
5
use Exception;
6
use Magium\Util\Log\Clairvoyant;
7
use Magium\Util\TestCase\RegistrationCallbackInterface;
8
use PHPUnit_Framework_AssertionFailedError;
9
use PHPUnit_Framework_Test;
10
use PHPUnit_Framework_TestSuite;
11
12
class MasterListener implements \PHPUnit_Framework_TestListener
13
{
14
15
    protected $replay = [];
16
    protected $listeners = [];
17
    protected $result;
18
19
    /**
20
     * @param $class
21
     * @return \PHPUnit_Framework_TestListener
22
     */
23
24
    public function getListener($class)
25
    {
26
        foreach ($this->listeners as $listener) {
27
            if (get_class($listener) == $class) {
28
                return $listener;
29
            }
30
        }
31
    }
32
33
    public function addListener(\PHPUnit_Framework_TestListener $listener)
34
    {
35
        foreach ($this->listeners as $existingListener) {
36
            if (get_class($listener) == get_class($existingListener)) {
37
                return;
38
            }
39
        }
40
        $this->listeners[] = $listener;
41
        foreach ($this->replay as $replay) {
42
            $this->play($replay['method'], $replay['args'], $listener);
43
        }
44
    }
45
46
    public function play($method, $args, \PHPUnit_Framework_TestListener $instance = null)
47
    {
48
        if ($instance instanceof \PHPUnit_Framework_TestListener) {
49
            call_user_func_array([$instance, $method], $args);
50
        } else {
51
            foreach ($this->listeners as $listener) {
52
                call_user_func_array([$listener, $method], $args);
53
            }
54
        }
55
    }
56
57
    public function bindToResult(\PHPUnit_Framework_TestResult $result)
58
    {
59
        if (!$this->result instanceof \PHPUnit_Framework_TestResult) {
60
            $this->result = $result;
61
            $result->addListener($this);
62
        }
63
    }
64
65
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
66
    {
67
        $this->replay[] = [
68
            'method' => __FUNCTION__,
69
            'args'  => func_get_args()
70
        ];
71
        $this->play(__FUNCTION__, func_get_args());
72
    }
73
74 View Code Duplication
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->replay[] = [
77
            'method' => __FUNCTION__,
78
            'args'  => func_get_args()
79
        ];
80
        $this->play(__FUNCTION__, func_get_args());
81
    }
82
83
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
84
    {
85
        $this->replay[] = [
86
            'method' => __FUNCTION__,
87
            'args'  => func_get_args()
88
        ];
89
        $this->play(__FUNCTION__, func_get_args());
90
    }
91
92
    public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
93
    {
94
        $this->replay[] = [
95
            'method' => __FUNCTION__,
96
            'args'  => func_get_args()
97
        ];
98
        $this->play(__FUNCTION__, func_get_args());
99
    }
100
101
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
102
    {
103
        $this->replay[] = [
104
            'method' => __FUNCTION__,
105
            'args'  => func_get_args()
106
        ];
107
        $this->play(__FUNCTION__, func_get_args());
108
    }
109
110 View Code Duplication
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        $this->replay[] = [
113
            'method' => __FUNCTION__,
114
            'args'  => func_get_args()
115
        ];
116
        $this->play(__FUNCTION__, func_get_args());
117
    }
118
119 View Code Duplication
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
    {
121
        $this->replay[] = [
122
            'method' => __FUNCTION__,
123
            'args'  => func_get_args()
124
        ];
125
        $this->play(__FUNCTION__, func_get_args());
126
    }
127
128 View Code Duplication
    public function startTest(PHPUnit_Framework_Test $test)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
    {
130
        $this->replay[] = [
131
            'method' => __FUNCTION__,
132
            'args'  => func_get_args()
133
        ];
134
        $this->play(__FUNCTION__, func_get_args());
135
    }
136
137 View Code Duplication
    public function endTest(PHPUnit_Framework_Test $test, $time)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
    {
139
        $this->replay[] = [
140
            'method' => __FUNCTION__,
141
            'args'  => func_get_args()
142
        ];
143
        $this->play(__FUNCTION__, func_get_args());
144
    }
145
146
}