66
77namespace Magento \TestFramework \Annotation ;
88
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 ;
1014use Magento \TestFramework \Fixture \ParserInterface ;
1115use Magento \TestFramework \Helper \Bootstrap ;
16+ use PHPUnit \Framework \TestCase ;
1217use RecursiveDirectoryIterator ;
1318use RecursiveIteratorIterator ;
19+ use ReflectionClass ;
1420use RegexIterator ;
21+ use SplFileInfo ;
22+ use Throwable ;
1523
1624/**
1725 * Implementation of the @magentoComponentsDir DocBlock annotation
26+ *
27+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1828 */
1929class ComponentRegistrarFixture
2030{
@@ -23,7 +33,7 @@ class ComponentRegistrarFixture
2333 /**#@+
2434 * Properties of components registrar
2535 */
26- public const REGISTRAR_CLASS = \ Magento \ Framework \ Component \ ComponentRegistrar::class;
36+ public const REGISTRAR_CLASS = ComponentRegistrar::class;
2737 public const PATHS_FIELD = 'paths ' ;
2838 /**#@-*/
2939
@@ -54,38 +64,38 @@ public function __construct($fixtureBaseDir)
5464 /**
5565 * Handler for 'startTest' event
5666 *
57- * @param \PHPUnit\Framework\ TestCase $test
67+ * @param TestCase $test
5868 * @return void
5969 */
60- public function startTest (\ PHPUnit \ Framework \ TestCase $ test )
70+ public function startTest (TestCase $ test )
6171 {
6272 $ this ->registerComponents ($ test );
6373 }
6474
6575 /**
6676 * Handler for 'endTest' event
6777 *
68- * @param \PHPUnit\Framework\ TestCase $test
78+ * @param TestCase $test
6979 * @return void
7080 *
7181 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
7282 */
73- public function endTest (\ PHPUnit \ Framework \ TestCase $ test )
83+ public function endTest (TestCase $ test )
7484 {
7585 $ this ->restoreComponents ();
7686 }
7787
7888 /**
7989 * Register fixture components
8090 *
81- * @param \PHPUnit\Framework\ TestCase $test
91+ * @param TestCase $test
8292 */
83- private function registerComponents (\ PHPUnit \ Framework \ TestCase $ test )
93+ private function registerComponents (TestCase $ test )
8494 {
8595 $ values = [];
8696 try {
8797 $ values = $ this ->parse ($ test );
88- } catch (\ Throwable $ exception ) {
98+ } catch (Throwable $ exception ) {
8999 ExceptionHandler::handle (
90100 'Unable to parse fixtures ' ,
91101 get_class ($ test ),
@@ -98,26 +108,26 @@ private function registerComponents(\PHPUnit\Framework\TestCase $test)
98108 }
99109
100110 $ componentAnnotations = array_unique (array_column ($ values , 'path ' ));
101- $ reflection = new \ ReflectionClass (self ::REGISTRAR_CLASS );
111+ $ reflection = new ReflectionClass (self ::REGISTRAR_CLASS );
102112 $ paths = $ reflection ->getProperty (self ::PATHS_FIELD );
103113 $ paths ->setAccessible (true );
104114 $ this ->origComponents = $ paths ->getValue ();
105115 $ paths ->setAccessible (false );
106116 foreach ($ componentAnnotations as $ fixturePath ) {
107117 $ fixturesDir = $ this ->fixtureBaseDir . '/ ' . $ fixturePath ;
108118 if (!file_exists ($ fixturesDir )) {
109- throw new \ InvalidArgumentException (
119+ throw new InvalidArgumentException (
110120 self ::ANNOTATION_NAME . " fixture ' $ fixturePath' does not exist "
111121 );
112122 }
113123 $ iterator = new RegexIterator (
114124 new RecursiveIteratorIterator (
115- new RecursiveDirectoryIterator ($ fixturesDir , \ FilesystemIterator::SKIP_DOTS )
125+ new RecursiveDirectoryIterator ($ fixturesDir , FilesystemIterator::SKIP_DOTS )
116126 ),
117127 '/^.+\/registration\.php$/ '
118128 );
119129 /**
120- * @var \ SplFileInfo $registrationFile
130+ * @var SplFileInfo $registrationFile
121131 */
122132 foreach ($ iterator as $ registrationFile ) {
123133 require $ registrationFile ->getRealPath ();
@@ -131,7 +141,7 @@ private function registerComponents(\PHPUnit\Framework\TestCase $test)
131141 private function restoreComponents ()
132142 {
133143 if (null !== $ this ->origComponents ) {
134- $ reflection = new \ ReflectionClass (self ::REGISTRAR_CLASS );
144+ $ reflection = new ReflectionClass (self ::REGISTRAR_CLASS );
135145 $ paths = $ reflection ->getProperty (self ::PATHS_FIELD );
136146 $ paths ->setAccessible (true );
137147 $ paths ->setValue ($ this ->origComponents );
@@ -143,16 +153,16 @@ private function restoreComponents()
143153 /**
144154 * Returns ComponentsDir fixtures configuration
145155 *
146- * @param \PHPUnit\Framework\ TestCase $test
156+ * @param TestCase $test
147157 * @return array
148- * @throws \Magento\Framework\Exception\ LocalizedException
158+ * @throws LocalizedException
149159 */
150- private function parse (\ PHPUnit \ Framework \ TestCase $ test ): array
160+ private function parse (TestCase $ test ): array
151161 {
152162 $ objectManager = Bootstrap::getObjectManager ();
153163 $ parsers = $ objectManager
154164 ->create (
155- \ Magento \ TestFramework \ Annotation \ Parser \ Composite::class,
165+ Composite::class,
156166 [
157167 'parsers ' => [
158168 $ objectManager ->get (\Magento \TestFramework \Annotation \Parser \ComponentsDir::class),
0 commit comments