6
6
7
7
namespace Magento \TestFramework \Annotation ;
8
8
9
- use Magento \TestFramework \Annotation \TestCaseAnnotation ;
9
+ use FilesystemIterator ;
10
+ use InvalidArgumentException ;
11
+ use Magento \Framework \Component \ComponentRegistrar ;
12
+ use Magento \Framework \Exception \LocalizedException ;
13
+ use Magento \TestFramework \Annotation \Parser \Composite ;
10
14
use Magento \TestFramework \Fixture \ParserInterface ;
11
15
use Magento \TestFramework \Helper \Bootstrap ;
16
+ use PHPUnit \Framework \TestCase ;
12
17
use RecursiveDirectoryIterator ;
13
18
use RecursiveIteratorIterator ;
19
+ use ReflectionClass ;
14
20
use RegexIterator ;
21
+ use SplFileInfo ;
22
+ use Throwable ;
15
23
16
24
/**
17
25
* Implementation of the @magentoComponentsDir DocBlock annotation
26
+ *
27
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
28
*/
19
29
class ComponentRegistrarFixture
20
30
{
@@ -23,7 +33,7 @@ class ComponentRegistrarFixture
23
33
/**#@+
24
34
* Properties of components registrar
25
35
*/
26
- public const REGISTRAR_CLASS = \ Magento \ Framework \ Component \ ComponentRegistrar::class;
36
+ public const REGISTRAR_CLASS = ComponentRegistrar::class;
27
37
public const PATHS_FIELD = 'paths ' ;
28
38
/**#@-*/
29
39
@@ -54,38 +64,38 @@ public function __construct($fixtureBaseDir)
54
64
/**
55
65
* Handler for 'startTest' event
56
66
*
57
- * @param \PHPUnit\Framework\ TestCase $test
67
+ * @param TestCase $test
58
68
* @return void
59
69
*/
60
- public function startTest (\ PHPUnit \ Framework \ TestCase $ test )
70
+ public function startTest (TestCase $ test )
61
71
{
62
72
$ this ->registerComponents ($ test );
63
73
}
64
74
65
75
/**
66
76
* Handler for 'endTest' event
67
77
*
68
- * @param \PHPUnit\Framework\ TestCase $test
78
+ * @param TestCase $test
69
79
* @return void
70
80
*
71
81
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
72
82
*/
73
- public function endTest (\ PHPUnit \ Framework \ TestCase $ test )
83
+ public function endTest (TestCase $ test )
74
84
{
75
85
$ this ->restoreComponents ();
76
86
}
77
87
78
88
/**
79
89
* Register fixture components
80
90
*
81
- * @param \PHPUnit\Framework\ TestCase $test
91
+ * @param TestCase $test
82
92
*/
83
- private function registerComponents (\ PHPUnit \ Framework \ TestCase $ test )
93
+ private function registerComponents (TestCase $ test )
84
94
{
85
95
$ values = [];
86
96
try {
87
97
$ values = $ this ->parse ($ test );
88
- } catch (\ Throwable $ exception ) {
98
+ } catch (Throwable $ exception ) {
89
99
ExceptionHandler::handle (
90
100
'Unable to parse fixtures ' ,
91
101
get_class ($ test ),
@@ -98,26 +108,26 @@ private function registerComponents(\PHPUnit\Framework\TestCase $test)
98
108
}
99
109
100
110
$ componentAnnotations = array_unique (array_column ($ values , 'path ' ));
101
- $ reflection = new \ ReflectionClass (self ::REGISTRAR_CLASS );
111
+ $ reflection = new ReflectionClass (self ::REGISTRAR_CLASS );
102
112
$ paths = $ reflection ->getProperty (self ::PATHS_FIELD );
103
113
$ paths ->setAccessible (true );
104
114
$ this ->origComponents = $ paths ->getValue ();
105
115
$ paths ->setAccessible (false );
106
116
foreach ($ componentAnnotations as $ fixturePath ) {
107
117
$ fixturesDir = $ this ->fixtureBaseDir . '/ ' . $ fixturePath ;
108
118
if (!file_exists ($ fixturesDir )) {
109
- throw new \ InvalidArgumentException (
119
+ throw new InvalidArgumentException (
110
120
self ::ANNOTATION_NAME . " fixture ' $ fixturePath' does not exist "
111
121
);
112
122
}
113
123
$ iterator = new RegexIterator (
114
124
new RecursiveIteratorIterator (
115
- new RecursiveDirectoryIterator ($ fixturesDir , \ FilesystemIterator::SKIP_DOTS )
125
+ new RecursiveDirectoryIterator ($ fixturesDir , FilesystemIterator::SKIP_DOTS )
116
126
),
117
127
'/^.+\/registration\.php$/ '
118
128
);
119
129
/**
120
- * @var \ SplFileInfo $registrationFile
130
+ * @var SplFileInfo $registrationFile
121
131
*/
122
132
foreach ($ iterator as $ registrationFile ) {
123
133
require $ registrationFile ->getRealPath ();
@@ -131,7 +141,7 @@ private function registerComponents(\PHPUnit\Framework\TestCase $test)
131
141
private function restoreComponents ()
132
142
{
133
143
if (null !== $ this ->origComponents ) {
134
- $ reflection = new \ ReflectionClass (self ::REGISTRAR_CLASS );
144
+ $ reflection = new ReflectionClass (self ::REGISTRAR_CLASS );
135
145
$ paths = $ reflection ->getProperty (self ::PATHS_FIELD );
136
146
$ paths ->setAccessible (true );
137
147
$ paths ->setValue ($ this ->origComponents );
@@ -143,16 +153,16 @@ private function restoreComponents()
143
153
/**
144
154
* Returns ComponentsDir fixtures configuration
145
155
*
146
- * @param \PHPUnit\Framework\ TestCase $test
156
+ * @param TestCase $test
147
157
* @return array
148
- * @throws \Magento\Framework\Exception\ LocalizedException
158
+ * @throws LocalizedException
149
159
*/
150
- private function parse (\ PHPUnit \ Framework \ TestCase $ test ): array
160
+ private function parse (TestCase $ test ): array
151
161
{
152
162
$ objectManager = Bootstrap::getObjectManager ();
153
163
$ parsers = $ objectManager
154
164
->create (
155
- \ Magento \ TestFramework \ Annotation \ Parser \ Composite::class,
165
+ Composite::class,
156
166
[
157
167
'parsers ' => [
158
168
$ objectManager ->get (\Magento \TestFramework \Annotation \Parser \ComponentsDir::class),
0 commit comments