@@ -66,21 +66,33 @@ public function endTest(\PHPUnit\Framework\TestCase $test)
66
66
{
67
67
$ annotations = $ test ->getAnnotations ();
68
68
//This annotation can be declared only on method level
69
- if (isset ($ annotations ['method ' ]['moduleName ' ])) {
69
+ if (! empty ($ annotations ['method ' ]['moduleName ' ])) {
70
70
foreach ($ annotations ['method ' ]['moduleName ' ] as $ moduleName ) {
71
71
$ path = MAGENTO_MODULES_PATH .
72
72
//Take only module name from Magento_ModuleName
73
73
explode ("_ " , $ moduleName )[1 ];
74
-
75
74
File::rmdirRecursive ($ path );
75
+ $ this ->unsergisterModuleFromComponentRegistrar ($ moduleName );
76
76
}
77
-
78
- $ reflection = new \ReflectionClass (ComponentRegistrar::class);
79
- $ reflectionProperty = $ reflection ->getProperty ('paths ' );
80
- $ reflectionProperty ->setAccessible (true );
81
- $ value = $ reflectionProperty ->getValue ();
82
- $ value [ComponentRegistrar::MODULE ] = [];
83
- $ reflectionProperty ->setValue ($ value );
84
77
}
85
78
}
79
+
80
+ /**
81
+ * Unregister module from component registrar.
82
+ * The component registrar uses static private variable and does not provide unregister method,
83
+ * however unregister is required to remove registered modules after they are deleted from app/code.
84
+ *
85
+ * @param $moduleName
86
+ *
87
+ * @return void
88
+ */
89
+ private function unsergisterModuleFromComponentRegistrar ($ moduleName )
90
+ {
91
+ $ reflection = new \ReflectionClass (ComponentRegistrar::class);
92
+ $ reflectionProperty = $ reflection ->getProperty ('paths ' );
93
+ $ reflectionProperty ->setAccessible (true );
94
+ $ value = $ reflectionProperty ->getValue ();
95
+ unset($ value [ComponentRegistrar::MODULE ][$ moduleName ]);
96
+ $ reflectionProperty ->setValue ($ value );
97
+ }
86
98
}
0 commit comments