7
7
8
8
namespace Magento \Setup \Test \Unit \Model ;
9
9
10
- use Magento \Setup \Model \FunctionOverrides ;
11
10
use Magento \Setup \Model \UninstallCollector ;
12
11
13
12
// phpcs:disable PSR1.Classes.ClassDeclaration
@@ -31,7 +30,9 @@ class UninstallCollectorTest extends \PHPUnit\Framework\TestCase
31
30
32
31
protected function setUp (): void
33
32
{
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
+
35
36
$ objectManagerProvider = $ this ->createMock (\Magento \Setup \Model \ObjectManagerProvider::class);
36
37
$ objectManager =
37
38
$ this ->getMockForAbstractClass (\Magento \Framework \ObjectManagerInterface::class, [], '' , false );
@@ -50,8 +51,8 @@ protected function setUp(): void
50
51
$ this ->result = $ this ->createMock (\Magento \Framework \DB \Select::class);
51
52
$ select ->expects ($ this ->once ())->method ('from ' )->willReturn ($ this ->result );
52
53
53
- $ uninstallA = 'Uninstall Class A ' ;
54
- $ uninstallB = 'Uninstall Class B ' ;
54
+ $ uninstallA = 'Magento\A\Setup\Uninstall ' ;
55
+ $ uninstallB = 'Magento\B\Setup\Uninstall ' ;
55
56
$ objectManager ->expects ($ this ->any ())
56
57
->method ('create ' )
57
58
->willReturnMap (
@@ -75,7 +76,7 @@ public function testUninstallCollector()
75
76
->willReturn ([['module ' => 'Magento_A ' ], ['module ' => 'Magento_B ' ], ['module ' => 'Magento_C ' ]]);
76
77
77
78
$ 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 ' ],
79
80
$ this ->collector ->collectUninstall ()
80
81
);
81
82
}
@@ -88,105 +89,10 @@ public function testUninstallCollectorWithInput()
88
89
->with ($ this ->result )
89
90
->willReturn ([['module ' => 'Magento_A ' ]]);
90
91
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 ' ]));
92
93
}
93
94
public function tearDown (): void
94
95
{
95
- FunctionOverrides::disable ();
96
96
parent ::tearDown ();
97
97
}
98
98
}
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