Search code examples
phptestingerror-handlingconfigurationbehat

Error when trying to run behat tests. usr/bin/env Invalid argument


I am trying to learn how to work with behat test. I am following this tutorial: https://www.mindyourownwebsite.com.au/installing-behat-3-mink-selenium-windows/

I managed to install everything that is required but when I get to the part where I have to run the behat tests:

/mypath/behat/bin/behat --config /projectPath/behat/behat.yml -p test:chrome 
/projectPath/behat/tests/

I got an error: /usr/bin/env php no such file or directory

I've made sure that I have php in my $PATH variable in git bash. Because nothing worked, I copied the php executable into /usr/bin/env:

cp /mypath/php/php.exe /usr/bin/env

Now when I try to run the behat test with the command mentioned above I get the error:

/usr/bin/env: Invalid argument

I really don't know what is the problem or how to fix this.

Thanks for any help!


Solution

  • Your issue might have been that you didn't add php to environment variables.

    Don't forget that after you add any env variable you need to restart any opened command line

    1. You don't need MAMP
    2. You need to install: php, composer, java, git
    3. For php extract and add the path to php.exe to Path environment variable
    4. Also for php you need to rename a php ini file to php.ini and enable the following extensions: curl, mbstring, openssl

    Behat
    1. You need a composer.json file that contains required packages
    2. Put this in a project directory, open command line or git bash there and execute
    composer install --prefer-dist
    3. Add your behat.yml config file in the same directory as composer file
    4. Run bin/behat --init to create the basic structure

    For large project I recommend to use it with page objects, you can also find extension for html report with included screenshot.