@@ -271,6 +271,91 @@ Feature: Evaluating PHP code and files.
271271 eval()'d code
272272 """
273273
274+ Scenario : Eval-file will not replace __FILE__ and __DIR__ in heredoc and nowdoc strings
275+ Given an empty directory
276+ And a script.php file:
277+ """
278+ <?php
279+ echo <<<TXT
280+ heredoc: __FILE__ __DIR__
281+
282+ TXT;
283+ echo <<<'TXT'
284+ nowdoc: __FILE__ __DIR__
285+
286+ TXT;
287+ echo 'code: ' . basename( __FILE__ ) . ' ' . basename( __DIR__ );
288+ """
289+
290+ When I run `wp eval-file script.php --skip-wordpress`
291+ Then STDOUT should contain:
292+ """
293+ heredoc: __FILE__ __DIR__
294+ """
295+ And STDOUT should contain:
296+ """
297+ nowdoc: __FILE__ __DIR__
298+ """
299+ And STDOUT should contain:
300+ """
301+ code: script.php
302+ """
303+ And STDOUT should not contain:
304+ """
305+ eval()'d code
306+ """
307+
308+ Scenario : Eval-file can handle large files with long strings
309+ Given an empty directory
310+ And a generate.php file:
311+ """
312+ <?php
313+ $links = str_repeat( '<a href="https://example.com/">it\'s "quoted"</a>' . PHP_EOL, 20000 );
314+ $text = str_repeat( 'a', 1024 * 1024 );
315+
316+ $script = "<?php\n";
317+ $script .= "\$links = <<<HTML\n{$links}\nHTML;\n";
318+ $script .= "\$text = '{$text}';\n";
319+ $script .= "echo basename( __FILE__ ), PHP_EOL, strlen( \$text ), PHP_EOL;\n";
320+
321+ file_put_contents( 'script.php', $script );
322+ """
323+
324+ When I run `wp eval-file generate.php --skip-wordpress`
325+ And I run `wp eval-file script.php --skip-wordpress`
326+ Then STDOUT should be:
327+ """
328+ script.php
329+ 1048576
330+ """
331+ And STDERR should be empty
332+
333+ Scenario : Eval-file only removes the shebang line at the start of the file
334+ Given an empty directory
335+ And a script.php file:
336+ """
337+ #!/usr/bin/env wp
338+ <?php
339+ echo <<<TXT
340+ #!not a shebang
341+ TXT;
342+ echo PHP_EOL, __LINE__;
343+ """
344+
345+ When I run `wp eval-file script.php --skip-wordpress`
346+ Then STDOUT should contain:
347+ """
348+ #!not a shebang
349+ """
350+ And STDOUT should contain:
351+ """
352+ 6
353+ """
354+ But STDOUT should not contain:
355+ """
356+ #!/usr/bin/env
357+ """
358+
274359 Scenario : Eval with --hook flag
275360 Given a WP install
276361
0 commit comments