@@ -239,10 +239,37 @@ public function testHandleBootsTheKernel()
239
239
$ kernel ->handle ($ request , $ type , $ catch );
240
240
}
241
241
242
- public function testStripComments ()
242
+ /**
243
+ * @dataProvider getStripCommentsCodes
244
+ */
245
+ public function testStripComments (string $ source , string $ expected )
246
+ {
247
+ $ output = Kernel::stripComments ($ source );
248
+
249
+ // Heredocs are preserved, making the output mixing Unix and Windows line
250
+ // endings, switching to "\n" everywhere on Windows to avoid failure.
251
+ if ('\\' === \DIRECTORY_SEPARATOR ) {
252
+ $ expected = str_replace ("\r\n" , "\n" , $ expected );
253
+ $ output = str_replace ("\r\n" , "\n" , $ output );
254
+ }
255
+
256
+ $ this ->assertEquals ($ expected , $ output );
257
+ }
258
+
259
+ public function getStripCommentsCodes (): array
243
260
{
244
- $ source = <<<'EOF'
261
+ return [
262
+ ['<?php echo foo(); ' , '<?php echo foo(); ' ],
263
+ ['<?php echo/**/foo(); ' , '<?php echo foo(); ' ],
264
+ ['<?php echo/** bar */foo(); ' , '<?php echo foo(); ' ],
265
+ ['<?php /**/echo foo(); ' , '<?php echo foo(); ' ],
266
+ ['<?php echo \foo(); ' , '<?php echo \foo(); ' ],
267
+ ['<?php echo/**/\foo(); ' , '<?php echo \foo(); ' ],
268
+ ['<?php echo/** bar */\foo(); ' , '<?php echo \foo(); ' ],
269
+ ['<?php /**/echo \foo(); ' , '<?php echo \foo(); ' ],
270
+ [<<<'EOF'
245
271
<?php
272
+ include_once \dirname(__DIR__).'/foo.php';
246
273
247
274
$string = 'string should not be modified';
248
275
@@ -280,9 +307,10 @@ public function doStuff()
280
307
// inline comment
281
308
}
282
309
}
283
- EOF;
284
- $ expected = <<<'EOF'
310
+ EOF
311
+ , <<<'EOF'
285
312
<?php
313
+ include_once \dirname(__DIR__).'/foo.php';
286
314
$string = 'string should not be modified';
287
315
$string = 'string should not be
288
316
@@ -307,18 +335,9 @@ public function doStuff()
307
335
{
308
336
}
309
337
}
310
- EOF;
311
-
312
- $ output = Kernel::stripComments ($ source );
313
-
314
- // Heredocs are preserved, making the output mixing Unix and Windows line
315
- // endings, switching to "\n" everywhere on Windows to avoid failure.
316
- if ('\\' === \DIRECTORY_SEPARATOR ) {
317
- $ expected = str_replace ("\r\n" , "\n" , $ expected );
318
- $ output = str_replace ("\r\n" , "\n" , $ output );
319
- }
320
-
321
- $ this ->assertEquals ($ expected , $ output );
338
+ EOF
339
+ ],
340
+ ];
322
341
}
323
342
324
343
/**
0 commit comments