12

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!

2
  • 2
    PHP usually shows you the complete path it was trying to access. Check this and compare it to the actual path's. This should show you what went wrong. Commented Aug 28, 2014 at 9:13
  • I had just had the same problem. I executed phpunit --bootstrap bootstrap.php PracticeTest while being in the came directory as the PracticeTest.php but I was using chdir() in my bootstrap file Commented Nov 29, 2019 at 22:34

5 Answers 5

8

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!!!!

Sign up to request clarification or add additional context in comments.

Comments

8

This is what worked for me.

vendor/bin/phpunit ./tests/PracticeTest

1 Comment

vendor/bin/phpunit C:\xampp\htdocs\unit_test_2\tests\CalculatorTest.php work for me.
1

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.

Comments

0

I had include_path sections separated by comma. It has to be semicolon on Windows.

1 Comment

use PATH_SEPARATOR constant like ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.'C:/PHP/PEAR/PHPUnit');
0

I have created a phpunit.bat in the root folder of my project containing

@ECHO OFF SET BIN_TARGET=%~dp0/vendor/phpunit/phpunit/phpunit php "%BIN_TARGET%" %*

Now it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.