16
16
use PHPUnit \Framework \Attributes \CoversClass ;
17
17
use PHPUnit \Framework \Attributes \DataProvider ;
18
18
use PHPUnit \Framework \TestCase ;
19
+ use ReflectionClass ;
19
20
use Symfony \Component \Console \Input \InputDefinition ;
20
21
use Symfony \Component \Filesystem \Filesystem ;
21
22
use Symfony \Component \Process \Process ;
@@ -111,8 +112,11 @@ public function test_it_can_create_a_configured_executor(): void
111
112
self ::assertEquals ($ expected , $ executor );
112
113
}
113
114
114
- public function test_it_escapes_the_php_executable_when_necessary (): void
115
- {
115
+ #[DataProvider('phpExecutableProvider ' )]
116
+ public function test_it_escapes_the_php_executable_when_necessary (
117
+ string |array $ phpExecutable ,
118
+ array $ expected ,
119
+ ): void {
116
120
$ commandName = 'import:items ' ;
117
121
$ definition = new InputDefinition ();
118
122
$ errorHandler = new FakeErrorHandler ();
@@ -121,32 +125,60 @@ public function test_it_escapes_the_php_executable_when_necessary(): void
121
125
$ callable1 = self ::createCallable (1 );
122
126
$ callable2 = self ::createCallable (2 );
123
127
124
- $ executorWithStringPhpExecutable = ParallelExecutorFactory::create (
128
+ $ factory = ParallelExecutorFactory::create (
125
129
$ callable0 ,
126
130
$ callable1 ,
127
131
$ callable2 ,
128
132
$ commandName ,
129
133
$ definition ,
130
134
$ errorHandler ,
131
135
)
132
- ->withPhpExecutable ('/path/to/php -dmemory_limit=128M ' )
133
- ->build ();
136
+ ->withPhpExecutable ($ phpExecutable );
134
137
135
- $ executorWithArrayPhpExecutable = ParallelExecutorFactory::create (
136
- $ callable0 ,
137
- $ callable1 ,
138
- $ callable2 ,
139
- $ commandName ,
140
- $ definition ,
141
- $ errorHandler ,
142
- )
143
- ->withPhpExecutable ([
144
- '/path/to/php ' ,
145
- '-dmemory_limit=128M ' ,
146
- ])
147
- ->build ();
138
+ $ phpExecutableReflection = (new ReflectionClass ($ factory ::class))->getProperty ('phpExecutable ' );
139
+ $ phpExecutableReflection ->setAccessible (true );
140
+
141
+ $ actual = $ phpExecutableReflection ->getValue ($ factory );
142
+
143
+ self ::assertSame ($ expected , $ actual );
144
+ }
148
145
149
- self ::assertEquals ($ executorWithArrayPhpExecutable , $ executorWithStringPhpExecutable );
146
+ public static function phpExecutableProvider (): iterable
147
+ {
148
+ yield 'simple path ' => [
149
+ '/path/to/php ' ,
150
+ ['/path/to/php ' ],
151
+ ];
152
+
153
+ yield 'path with space ' => [
154
+ '/path/to/my php ' ,
155
+ ['/path/to/my php ' ],
156
+ ];
157
+
158
+ yield 'path with space (array) ' => [
159
+ ['/path/to/my php ' ],
160
+ ['/path/to/my php ' ],
161
+ ];
162
+
163
+ yield 'path with php setting (incorrect) ' => [
164
+ '/path/to/php -dmemory_limit=128M ' ,
165
+ ['/path/to/php -dmemory_limit=128M ' ],
166
+ ];
167
+
168
+ yield 'path with php setting (array) ' => [
169
+ ['/path/to/php ' , '-dmemory_limit=128M ' ],
170
+ ['/path/to/php ' , '-dmemory_limit=128M ' ],
171
+ ];
172
+
173
+ yield 'path with space and with php setting (incorrect) ' => [
174
+ '/path/to/my php -dmemory_limit=128M ' ,
175
+ ['/path/to/my php -dmemory_limit=128M ' ],
176
+ ];
177
+
178
+ yield 'path with space and with php setting (array) ' => [
179
+ ['/path/to/my php ' , '-dmemory_limit=128M ' ],
180
+ ['/path/to/my php ' , '-dmemory_limit=128M ' ],
181
+ ];
150
182
}
151
183
152
184
public function test_it_sets_the_batch_size_to_the_segment_size_by_default (): void
@@ -234,7 +266,7 @@ public function test_it_can_create_an_executor_with_default_values(
234
266
string $ expectedSymbol ,
235
267
string $ expectedPhpExecutable ,
236
268
string $ expectedScriptPath ,
237
- string $ expectedWorkingDirectory
269
+ string $ expectedWorkingDirectory,
238
270
): void {
239
271
$ cleanUpWorkingDirectory = self ::moveToWorkingDirectory ($ workingDirectory );
240
272
$ cleanUpEnvironmentVariables = EnvironmentVariables::setVariables ($ environmentVariables );
0 commit comments