@@ -248,3 +248,88 @@ Feature: Evaluating PHP code and files.
248248 """
249249 eval()'d code
250250 """
251+
252+ Scenario : Eval with --hook flag
253+ Given a WP install
254+
255+ When I run `wp eval 'echo "Hook: " . current_action();' --hook=init`
256+ Then STDOUT should contain:
257+ """
258+ Hook: init
259+ """
260+
261+ When I run `wp eval 'echo "Hook: " . current_action();' --hook=wp_loaded`
262+ Then STDOUT should contain:
263+ """
264+ Hook: wp_loaded
265+ """
266+
267+ Scenario : Eval-file with --hook flag
268+ Given a WP install
269+ And a hook-script.php file:
270+ """
271+ <?php
272+ echo "Hook: " . current_action() . "\n";
273+ echo "Is admin: " . (is_admin() ? 'yes' : 'no') . "\n";
274+ """
275+
276+ When I run `wp eval-file hook-script.php --hook=init`
277+ Then STDOUT should contain:
278+ """
279+ Hook: init
280+ """
281+ And STDOUT should contain:
282+ """
283+ Is admin:
284+ """
285+
286+ When I run `wp eval-file hook-script.php --hook=wp_loaded`
287+ Then STDOUT should contain:
288+ """
289+ Hook: wp_loaded
290+ """
291+
292+ Scenario : Eval with --hook and --skip-wordpress should error
293+ Given a WP install
294+
295+ When I try `wp eval 'echo "test";' --hook=init --skip-wordpress`
296+ Then STDERR should contain:
297+ """
298+ Error: The --hook parameter cannot be used with --skip-wordpress.
299+ """
300+ And the return code should be 1
301+
302+ Scenario : Eval-file with --hook and --skip-wordpress should error
303+ Given an empty directory
304+ And a script.php file:
305+ """
306+ <?php
307+ echo "test";
308+ """
309+
310+ When I try `wp eval-file script.php --hook=init --skip-wordpress`
311+ Then STDERR should contain:
312+ """
313+ Error: The --hook parameter cannot be used with --skip-wordpress.
314+ """
315+ And the return code should be 1
316+
317+ Scenario : Eval-file with --hook and positional arguments
318+ Given a WP install
319+ And a args-script.php file:
320+ """
321+ <?php
322+ echo "Hook: " . current_action() . "\n";
323+ echo "Args: " . implode(' ', $args) . "\n";
324+ """
325+
326+ When I run `wp eval-file args-script.php arg1 arg2 --hook=init`
327+ Then STDOUT should contain:
328+ """
329+ Hook: init
330+ """
331+ And STDOUT should contain:
332+ """
333+ Args: arg1 arg2
334+ """
335+
0 commit comments