Laravel Vagrant在PHP CLI中运行artisan命令

I am using Laravel 5.4 with Homestead vagrant and running my app on vagrant where i run tests like vagrant@homestead:~/ticketApp$ php artisan dusk and it works fine. currently i need to apply a hack where i put a check in my code that

if ('cli' === PHP_SAPI) {
   // do something
}

and run the command php php artisan dusk but the condition 'cli' === PHP_SAPI didn't return true and when i print the PHP_SAPI it returns the fpm-cgi.

whereas i was expecting that PHP_SAPI will return cli.

Please help how i'll run my tests to make this condition true

Try run command

php-cli artisan dusk

Ok, check documentation for you Laravel version, modern frameworks implements build-in functional for check request type, example:

if (App::runningInConsole())
      echo "Running in artisan/CLI";
    else 
      echo "Running in a browser";

from here How can a Laravel 4 class detect that it is running in an Artisan task vs. a browser request?