phpunit command doesn't work for laravel 4 on windows 7

前端 未结 11 1775
南笙
南笙 2020-12-15 06:06

I\'ve recently installed laravel and have written some tests in /tests directory but when I use phpunit at cmd in the same folder that phpunit.xml

相关标签:
11条回答
  • 2020-12-15 06:13

    If you are a window user and you are having this issue, do this:

    You need to tell Window where to find PHPUnit command, you can first of all verify that this file exists in your Laravel project under /vendor/bin

    enter image description here

    Finally you need to append the full path to /vendor/bin in your window PATH variable,

    To do this: 1. Right-click on 'Computer' then click properties

    enter image description here

    1. On the second window click Advanced system settings

    enter image description here

    1. On the next window under Advanced click Environmental Variables

    enter image description here

    1. On the next window double-click PATH then set PATH variable by appending

    the full path to your laravel-project/vendor/bin; Notice the ; at the end.

    NB: Other variables might already exists in the PATH, so ensure you don't overwrite them by appending your own at the very end

    1. Finally click Ok on all the dialog boxes

    enter image description here

    0 讨论(0)
  • 2020-12-15 06:13
    alias phpunit="vendor/bin/phpunit"
    
    0 讨论(0)
  • 2020-12-15 06:15

    With Laravel phpunit is set up right out of the box. The easiest way to run it on Windows is to add an entry to scripts in your package.json file...

    "scripts": {
        ...
        "tests": "php vendor/phpunit/phpunit/phpunit"
    },
    

    Now you simply run unit tests with

    npm run tests
    
    0 讨论(0)
  • 2020-12-15 06:16

    I added this command in command line instead of just "phpunit"

    vendor\bin\phpunit
    

    That worked for me.

    0 讨论(0)
  • 2020-12-15 06:20

    Install phpunit globally:

    composer global require phpunit/phpunit
    

    Afterwards you will be able to run phpunit ( even on Windows ):

    phpunit
    
    0 讨论(0)
  • 2020-12-15 06:23

    Borrowing from @Chris' excellent answer:
    Even better, you can make vendor/phpunit/phpunit/phpunit an environment variable, say "phpunit" and whenever you want to run the test in any laravel project you just call php %phpunit%.

    Demonstration

    0 讨论(0)
提交回复
热议问题