15
votes

I have a Laravel app installed in my directory f:\lara_app. I use PHP artisan serve to run the app. I have Laravel version 5.4.36 (via Composer Install)

I am not trying my hand in using the PHP Unit to do testing. Inside f:/lara_app/tests/Unit/ExampleTest.php, I have the following codes:

namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
         $this->assertTrue(true);
    }

    public function myFirstTest()
    {
        $value = 'Hello World';
        $this->assertTrue( 'Hello' === $value, 'Value should be Hello World');
    }     
}

I now try to run the test from my command prompt:

f:\lara_app> .vendor/phpunit/phpuni/phpunit

But I'm getting the message below:

'.vendor' is not recognized as an internal or external command, operable program or batch file

How do I run the PHPUnit test?

Thanks in advance

7
your answer is in your question. why the . before vendor?Wreigh
The tutorial I'm following has the . before the vendor - the author is using a Mac though. I thought the shell commands would be the same in both platformsJaime Dolor jr.

7 Answers

41
votes

Use quotes:

"./vendor/bin/phpunit"
21
votes

This should work on windows

f:\lara_app> php vendor/phpunit/phpunit/phpunit
6
votes

This works for me

C:\code\project-name> vendor\bin\phpunit
4
votes

For every Laravel project from version 7.x, if you want to run tests you can do one of these:

  • You can use artisan: php artisan test docs
  • Or you can use phpunit: if you want to run phpunit on windows, only by typing phpunit, you can create a bat file in your project's main directory by running this command:@echo php vendor\phpunit\phpunit\phpunit > phpunit.bat and then you can type phpunit in your command and enjoy.

Happy Testing...

1
votes

Also for future readers, you can run it on windows powershell, without having to change anything, if you're in the root directory of your project. Simply Type

./vendor/bin/phpunit
0
votes

Use quotes or use backslashes. Unlike linux, Windows does not like forward slashes.

0
votes

Check if you have phpunit in composer.json, and run:

composer update

And then run PHPUnit:

vendor/bin/phpunit