kfirba
kfirba

Reputation: 5441

PHPUnit cannot open file

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:

Thanks in advance!

Upvotes: 12

Views: 26232

Answers (5)

jakebugz617
jakebugz617

Reputation: 349

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.

Upvotes: 1

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.

Upvotes: 0

Arosha De Silva
Arosha De Silva

Reputation: 597

This is what worked for me.

vendor/bin/phpunit ./tests/PracticeTest

Upvotes: 8

Damian Jimenez
Damian Jimenez

Reputation: 89

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

Upvotes: 8

Slawa
Slawa

Reputation: 1217

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

Upvotes: 0

Related Questions