77
88namespace Magento \Setup \Test \Unit \Model ;
99
10- use Magento \Setup \Model \FunctionOverrides ;
1110use Magento \Setup \Model \UninstallCollector ;
1211
1312// phpcs:disable PSR1.Classes.ClassDeclaration
@@ -31,7 +30,9 @@ class UninstallCollectorTest extends \PHPUnit\Framework\TestCase
3130
3231 protected function setUp (): void
3332 {
34- FunctionOverrides::enable ();
33+ require_once '_files/app/code/Magento/A/Setup/Uninstall.php ' ;
34+ require_once '_files/app/code/Magento/B/Setup/Uninstall.php ' ;
35+
3536 $ objectManagerProvider = $ this ->createMock (\Magento \Setup \Model \ObjectManagerProvider::class);
3637 $ objectManager =
3738 $ this ->getMockForAbstractClass (\Magento \Framework \ObjectManagerInterface::class, [], '' , false );
@@ -50,8 +51,8 @@ protected function setUp(): void
5051 $ this ->result = $ this ->createMock (\Magento \Framework \DB \Select::class);
5152 $ select ->expects ($ this ->once ())->method ('from ' )->willReturn ($ this ->result );
5253
53- $ uninstallA = 'Uninstall Class A ' ;
54- $ uninstallB = 'Uninstall Class B ' ;
54+ $ uninstallA = 'Magento\A\Setup\Uninstall ' ;
55+ $ uninstallB = 'Magento\B\Setup\Uninstall ' ;
5556 $ objectManager ->expects ($ this ->any ())
5657 ->method ('create ' )
5758 ->willReturnMap (
@@ -75,7 +76,7 @@ public function testUninstallCollector()
7576 ->willReturn ([['module ' => 'Magento_A ' ], ['module ' => 'Magento_B ' ], ['module ' => 'Magento_C ' ]]);
7677
7778 $ this ->assertEquals (
78- ['Magento_A ' => 'Uninstall Class A ' , 'Magento_B ' => 'Uninstall Class B ' ],
79+ ['Magento_A ' => 'Magento\A\Setup\Uninstall ' , 'Magento_B ' => 'Magento\B\Setup\Uninstall ' ],
7980 $ this ->collector ->collectUninstall ()
8081 );
8182 }
@@ -88,105 +89,10 @@ public function testUninstallCollectorWithInput()
8889 ->with ($ this ->result )
8990 ->willReturn ([['module ' => 'Magento_A ' ]]);
9091
91- $ this ->assertEquals (['Magento_A ' => 'Uninstall Class A ' ], $ this ->collector ->collectUninstall (['Magento_A ' ]));
92+ $ this ->assertEquals (['Magento_A ' => 'Magento\A\Setup\Uninstall ' ], $ this ->collector ->collectUninstall (['Magento_A ' ]));
9293 }
9394 public function tearDown (): void
9495 {
95- FunctionOverrides::disable ();
9696 parent ::tearDown ();
9797 }
9898}
99-
100- namespace Magento \Setup \Model ;
101-
102- /**
103- * This function overrides the native function for the purpose of testing
104- *
105- * @param string $obj
106- * @param string $className
107- * @return bool
108- */
109- function is_subclass_of ($ obj , $ className )
110- {
111- return FunctionOverrides::is_subclass_of ($ obj , $ className );
112- }
113-
114- /**
115- * This function overrides the native function for the purpose of testing
116- *
117- * @param string $className
118- * @return bool
119- */
120- function class_exists ($ className )
121- {
122- return FunctionOverrides::class_exists ($ className );
123- }
124-
125- /**
126- * This class is used to override the native functions for the purpose of testing
127- */
128- class FunctionOverrides
129- {
130- /**
131- * @var bool
132- */
133- private static bool $ enabled = false ;
134-
135- /**
136- * Check if the function overrides are enabled
137- *
138- * @return void
139- */
140- public static function enable (): void
141- {
142- self ::$ enabled = true ;
143- }
144-
145- /**
146- * Check if the function overrides are disabled
147- *
148- * @return void
149- */
150- public static function disable (): void
151- {
152- self ::$ enabled = false ;
153- }
154-
155- /**
156- * Check if the object is a subclass of the given class name
157- *
158- * @param $obj
159- * @param $className
160- * @return bool
161- */
162- public static function is_subclass_of ($ obj , $ className ): bool
163- {
164- if (!self ::$ enabled ) {
165- return \is_subclass_of ($ obj , $ className );
166- }
167- if ($ obj == 'Uninstall Class A ' && $ className == \Magento \Framework \Setup \UninstallInterface::class) {
168- return true ;
169- }
170- if ($ obj == 'Uninstall Class B ' && $ className == \Magento \Framework \Setup \UninstallInterface::class) {
171- return true ;
172- }
173- return false ;
174- }
175-
176- /**
177- * Check if the class exists of the given class name
178- *
179- * @param $className
180- * @return bool
181- */
182- public static function class_exists ($ className ): bool
183- {
184- if (!self ::$ enabled ) {
185- return \class_exists ($ className );
186- }
187- if ($ className == 'Magento\A\Setup\Uninstall ' || $ className == 'Magento\B\Setup\Uninstall ' ) {
188- return true ;
189- }
190- return false ;
191- }
192- }
0 commit comments