9
9
*/
10
10
namespace Magento \TestFramework \Event ;
11
11
12
+ use Magento \Framework \Exception \LocalizedException ;
13
+ use Magento \TestFramework \EventManager ;
14
+ use PHPUnit \Framework \AssertionFailedError ;
15
+ use PHPUnit \Framework \DataProviderTestSuite ;
16
+ use PHPUnit \Framework \Test ;
17
+ use PHPUnit \Framework \TestCase ;
18
+ use PHPUnit \Framework \TestSuite ;
19
+ use PHPUnit \Framework \Warning ;
20
+
12
21
class PhpUnit implements \PHPUnit \Framework \TestListener
13
22
{
14
23
/**
15
24
* Used when PHPUnit framework instantiates the class on its own and passes nothing to the constructor
16
25
*
17
- * @var \Magento\TestFramework\ EventManager
26
+ * @var EventManager
18
27
*/
19
28
protected static $ _defaultEventManager ;
20
29
21
30
/**
22
- * @var \Magento\TestFramework\ EventManager
31
+ * @var EventManager
23
32
*/
24
33
protected $ _eventManager ;
25
34
26
35
/**
27
36
* Assign default event manager instance
28
37
*
29
- * @param \Magento\TestFramework\ EventManager $eventManager
38
+ * @param EventManager $eventManager
30
39
*/
31
- public static function setDefaultEventManager (\ Magento \ TestFramework \ EventManager $ eventManager = null )
40
+ public static function setDefaultEventManager (EventManager $ eventManager = null ): void
32
41
{
33
42
self ::$ _defaultEventManager = $ eventManager ;
34
43
}
35
44
36
45
/**
37
46
* Constructor
38
47
*
39
- * @param \Magento\TestFramework\ EventManager $eventManager
40
- * @throws \Magento\Framework\Exception\ LocalizedException
48
+ * @param EventManager $eventManager
49
+ * @throws LocalizedException
41
50
*/
42
- public function __construct (\ Magento \ TestFramework \ EventManager $ eventManager = null )
51
+ public function __construct (EventManager $ eventManager = null )
43
52
{
44
53
$ this ->_eventManager = $ eventManager ?: self ::$ _defaultEventManager ;
45
54
if (!$ this ->_eventManager ) {
46
- throw new \ Magento \ Framework \ Exception \ LocalizedException (__ ('Instance of the event manager is required. ' ));
55
+ throw new LocalizedException (__ ('Instance of the event manager is required. ' ));
47
56
}
48
57
}
49
58
@@ -52,7 +61,7 @@ public function __construct(\Magento\TestFramework\EventManager $eventManager =
52
61
* @SuppressWarnings(PHPMD.ShortVariable)
53
62
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
54
63
*/
55
- public function addError (\ PHPUnit \ Framework \ Test $ test , \Exception $ e , $ time )
64
+ public function addError (Test $ test , \Throwable $ e , float $ time ): void
56
65
{
57
66
}
58
67
@@ -61,7 +70,7 @@ public function addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
61
70
* @SuppressWarnings(PHPMD.ShortVariable)
62
71
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
63
72
*/
64
- public function addFailure (\ PHPUnit \ Framework \ Test $ test , \ PHPUnit \ Framework \ AssertionFailedError $ e , $ time )
73
+ public function addFailure (Test $ test , AssertionFailedError $ e , float $ time ): void
65
74
{
66
75
}
67
76
@@ -70,7 +79,7 @@ public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Ass
70
79
* @SuppressWarnings(PHPMD.ShortVariable)
71
80
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
72
81
*/
73
- public function addIncompleteTest (\ PHPUnit \ Framework \ Test $ test , \Exception $ e , $ time )
82
+ public function addIncompleteTest (Test $ test , \Throwable $ e , float $ time ): void
74
83
{
75
84
}
76
85
@@ -79,7 +88,7 @@ public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e,
79
88
* @SuppressWarnings(PHPMD.ShortVariable)
80
89
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
81
90
*/
82
- public function addRiskyTest (\ PHPUnit \ Framework \ Test $ test , \Exception $ e , $ time )
91
+ public function addRiskyTest (Test $ test , \Throwable $ e , float $ time ): void
83
92
{
84
93
}
85
94
@@ -88,17 +97,17 @@ public function addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time
88
97
* @SuppressWarnings(PHPMD.ShortVariable)
89
98
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
90
99
*/
91
- public function addSkippedTest (\ PHPUnit \ Framework \ Test $ test , \Exception $ e , $ time )
100
+ public function addSkippedTest (Test $ test , \Throwable $ e , float $ time ): void
92
101
{
93
102
}
94
103
95
104
/**
96
105
* {@inheritdoc}
97
106
*/
98
- public function startTestSuite (\ PHPUnit \ Framework \ TestSuite $ suite )
107
+ public function startTestSuite (TestSuite $ suite ): void
99
108
{
100
109
/* PHPUnit runs tests with data provider in own test suite for each test, so just skip such test suites */
101
- if ($ suite instanceof \ PHPUnit \ Framework \ DataProviderTestSuite) {
110
+ if ($ suite instanceof DataProviderTestSuite) {
102
111
return ;
103
112
}
104
113
$ this ->_eventManager ->fireEvent ('startTestSuite ' );
@@ -107,9 +116,9 @@ public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
107
116
/**
108
117
* {@inheritdoc}
109
118
*/
110
- public function endTestSuite (\ PHPUnit \ Framework \ TestSuite $ suite )
119
+ public function endTestSuite (TestSuite $ suite ): void
111
120
{
112
- if ($ suite instanceof \ PHPUnit \ Framework \ DataProviderTestSuite) {
121
+ if ($ suite instanceof DataProviderTestSuite) {
113
122
return ;
114
123
}
115
124
$ this ->_eventManager ->fireEvent ('endTestSuite ' , [$ suite ], true );
@@ -118,9 +127,9 @@ public function endTestSuite(\PHPUnit\Framework\TestSuite $suite)
118
127
/**
119
128
* {@inheritdoc}
120
129
*/
121
- public function startTest (\ PHPUnit \ Framework \ Test $ test )
130
+ public function startTest (Test $ test ): void
122
131
{
123
- if (!$ test instanceof \ PHPUnit \ Framework \ TestCase || $ test instanceof \ PHPUnit \ Framework \ Warning) {
132
+ if (!$ test instanceof TestCase || $ test instanceof Warning) {
124
133
return ;
125
134
}
126
135
$ this ->_eventManager ->fireEvent ('startTest ' , [$ test ]);
@@ -130,9 +139,9 @@ public function startTest(\PHPUnit\Framework\Test $test)
130
139
* {@inheritdoc}
131
140
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
132
141
*/
133
- public function endTest (\ PHPUnit \ Framework \ Test $ test , $ time )
142
+ public function endTest (Test $ test , float $ time ): void
134
143
{
135
- if (!$ test instanceof \ PHPUnit \ Framework \ TestCase || $ test instanceof \ PHPUnit \ Framework \ Warning) {
144
+ if (!$ test instanceof TestCase || $ test instanceof Warning) {
136
145
return ;
137
146
}
138
147
$ this ->_eventManager ->fireEvent ('endTest ' , [$ test ], true );
@@ -141,7 +150,7 @@ public function endTest(\PHPUnit\Framework\Test $test, $time)
141
150
/**
142
151
* {@inheritdoc}
143
152
*/
144
- public function addWarning (\ PHPUnit \ Framework \ Test $ test , \ PHPUnit \ Framework \ Warning $ e , $ time )
153
+ public function addWarning (Test $ test , Warning $ e , float $ time ): void
145
154
{
146
155
}
147
156
}
0 commit comments