phpunit: Testcase does not open, throws ' Cannot open file "mytest.php" '

Hi, I have installed PHPUnit 3.5.14 using the Pear package installation on my sandbox that runs CentOS 5.2

When I tried to execute my testcases located at the location:

    /var/www/testcases/mytest.php

using the terminal command:

    phpunit mytest.php

This is throwing me the following error:

PHPUnit 3.5.14 by Sebastian Bergmann.

Cannot open file “mytest.php”.

I have even tried to uninstall and reinstall phpunit, but then its still throwing the same error. The code inside mytest.php is as follows:

<?php class mytest extends PHPUnit_Framework_TestCase { public function testOne() { $this->assertTrue(FALSE); } ``` /** * @depends testOne */ public function testTwo() { } ``` } ?>

Any help would be highy appreciated. Thanks for looking into my post.

Regards, LoGiX

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 19 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Are you using “tab” for complete the address to the file? if you are doing that stop doing it, write the address manually 😃

I am still having this issue. I call php unit on the file with and without the “.php” extension. I reference the bootstrap.php file in my xml correctly and I also have tried referencing it explicitly with “–bootstrap”. I can also run another test file in the same folder just fine. All of them actually except this one. They all have the same permissions. OrganizationTest.php is the problem file.

noahgary@Noahs-MBP:~/Projects/han-api/infrastructure/Testing/Unit$ ls -l
total 80
-rw-r--r--  1 noahgary  staff   2.2K Apr 12 12:59 CartTypeTest.php
-rw-r--r--  1 noahgary  staff   2.4K Apr 12 12:59 ConditionTest.php
-rw-r--r--  1 noahgary  staff   2.4K Apr 12 12:59 CountryTest.php
-rw-r--r--  1 noahgary  staff   2.2K Apr 12 12:59 FeeTypeTest.php
-rw-r--r--  1 noahgary  staff   2.6K Apr 12 12:59 OrderItemStatusTest.php
-rw-r--r--  1 noahgary  staff   2.4K Apr 12 12:59 OrderStatusTest.php
-rw-r--r--  1 noahgary  staff   2.6K Apr 12 17:05 OrganizationTest.php
-rw-r--r--  1 noahgary  staff   2.7K Apr 12 12:59 OrganizationTypeTest.php
-rw-r--r--  1 noahgary  staff   2.5K Apr 12 12:59 QuantityTypeTest.php
-rw-r--r--  1 noahgary  staff   2.3K Apr 12 16:52 UserTest.php

UPDATE: The test runs if I run it with all the others. I cannot run it alone though which adds approx. 5 min to each run while I’m trying to get these tests working.

UPDATE-2: Quick workaround is the “–filter” flag. It allows you to run just one test out of the batch.

e.g. vendor/bin/phpunit --filter OrganizationTest

In case anybody fall here from a Google search, I had the same problem, but my file was Bootstrap.php and I solved the issue renaming its name to bootstrap.php (all lowercase).

In my case, just adding ‘.php’ at the end of the filename worked. Instead of ‘phpunit CarTest’ use ‘phpunit CarTest.php’.

I hope it helps. 😄

Same for me. Simply adding the “–filter” flag worked. Otherwise it didn’t.

if you use the full path it should be okay for example when I used unit --bootstrap “C:\xampp\htdocs\general-php\vendor\autoload.php” tests issue resolved

Ran through same issue, had not fixed path to the bootstrap.php on the phpunit.xml file…

Disclaimer: Posting on this closed issue because is the closest I got of an issue like mine, and it might be useful to someone else…

For anyone that may still be facing this issue, check if ‘safe_mode = On’ on /etc/php5/cli/php.ini. Switching it to ‘safe_mode = Off’ will do the trick. In my case, I was trying to execute files owned by the current user - which is not root - that in turn would include PHPUnit files - owned by root. Something not allowed when safemode is on. Both users must have the same id.

It would have saved me hours of hair pulling if I found out it earlier 😕