"""
Notice: Use of undefined constant CONST_WITHOUT_QUOTES
"""
+
+ Scenario: Setting the WP user
+ Given WP install
+
+ When I run `wp eval 'echo (int) is_user_logged_in();'`
+ Then it should run without errors
+ And STDOUT should be:
+ """
+ 0
+ """
+
+ When I run `wp --user=admin eval 'echo wp_get_current_user()->user_login;'`
+ Then it should run without errors
+ And STDOUT should be:
+ """
+ admin
+ """
+
+ When I run `wp --user=non-existing-user`
+ Then the return code should be 1
+ And STDERR should be:
+ """
+ Error: Could not get a user_id for this user: 'non-existing-user'
+ """
$steps->When( '/^I run `(.+)`$/',
function ( $world, $cmd ) {
- $cmd = ltrim( str_replace( 'wp', '', $cmd ) );
+ if ( 0 === strpos( $cmd, 'wp' ) ) {
+ $cmd = ltrim( substr( $cmd, 2 ) );
+ }
$world->replace_variables( $cmd );