I've started learning how to use PHPUnit. However, I'm facing a problem which I have no clue how to solve.
I have a folder called lessons
and inside there is a composer.json
which I installed PHPUnit with.
The output resulted in a folder called vendor
and a sub-folder called bin
which has the phpunit file in it.
In the cmd
I typed: cd c:/xampp/htdocs/lessons/vendor/bin
. Now the cmd folder sets to the same folder as phpunit. I've created a directory in lessons
which I called tests
(lessons/tests
) which I store all of my tests in. I've created a file called PracticeTest.php
with a very simple test script in it.
When I go back to the cmd
and type phpunit tests
I get cannot open file tests.php
When I try to type phpunit PracticeTest
I get cannot open file PracticeTest.php
. When I try phpunit tests/PracticeTest
(with .php
or without) I get the same error that the file could not be opened.
My suspicious that it has something to do with that face that the cmd
is pointing at the lessons/vendor/bin
directory, but I'm not sure if it is really the problem or how to fix it.
just to arrange the paths:
lessons\vendor\bin\
lessons\tests\
lessons\tests\PracticeTest.php
Thanks in advance!
This is what worked for me.
vendor/bin/phpunit ./tests/PracticeTest
I was getting the same, but if you type phpunit
then tab you will see what directory you are in and it should autosuggest. Then navigate to your test file.
Go to path project:
D:\>cd www
D:\wwww>cd lessons
And execute:
D:\www\lessons>vendor\bin\phpunit tests
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.
.....E.
Time: 1.34 seconds, Memory: 5.50MB
There was 1 error:
1) UserTest::it_should_be_able_to_construct
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert
:assertInstanceOf() must be a class or interface name
D:\www\lessons\tests\UserTest.php:10
FAILURES!
Tests: 7, Assertions: 4, Errors: 1.
It Works!!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With