12

I'm trying to run phpunit within a Yii2 basic installation but whenever I run php vendor/bin/phpunit from the command line I get this output:

Note: I am on Windows 7.

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"

Can anyone advise what the issue is here? I haven't used phpunit before so unsure what is happening.

Brett
  • 19,449
  • 54
  • 157
  • 290
  • Have you checked [this SO question](http://stackoverflow.com/questions/2266661/cygwin-and-phpunit-could-not-open-input-file-cygdrive-c-xampp-php-phpunit)? – Bizley Nov 19 '16 at 18:24
  • @Bizley Thanks, I'll have a look. – Brett Nov 19 '16 at 18:54

2 Answers2

17

Well, it was an obvious solution:

File vendor/bin/phpunit is not a PHP script, but a shell script.

Remove php from the start and simply run vendor/bin/phpunit.

Source.

Brett
  • 19,449
  • 54
  • 157
  • 290
  • Hello Brett, I have tried command without PHP, but with out it PHP extended class is not finding in call. here is error: Fatal error: Class 'PHPUnit_Framework_TestCase' not found in \tests\ProgrammerControllerTest.php on line 8 – JayminLimbachiya Mar 20 '19 at 10:24
  • @Jaymin I'm not 100% sure I follow your problem - perhaps you could create a new question with more info? – Brett Mar 20 '19 at 16:50
  • removing php I am getting `'php' is not recognized as an internal or external command`, and with php it prints what 's inside that file the shell script you mentioned. As mentioned in the question it simply output the script – Syed Waqas Bukhary Sep 18 '21 at 04:24
0

Removing php from command I am getting 'php' is not recognized as an internal or external command, and with php it prints what 's inside that file the shell script you mentioned. As mentioned in the question it simply output the script

To fix this

  • Add php to path as explained here

Or

  • For temporary use, try this: (benefit for use npm or composer)
    SET PATH=c:\wamp\bin\php\php5.3.29\;%PATH%
Syed Waqas Bukhary
  • 5,130
  • 5
  • 47
  • 59