Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testcase does not open, throws ' Cannot open file "mytest.php" ' #279

Closed
vairav opened this issue Jun 23, 2011 · 19 comments
Closed

Testcase does not open, throws ' Cannot open file "mytest.php" ' #279

vairav opened this issue Jun 23, 2011 · 19 comments

Comments

@vairav
Copy link

vairav commented Jun 23, 2011

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:

assertTrue(FALSE); } ``` /** * @Depends testOne */ public function testTwo() { } ``` } ?>

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

Regards,
LoGiX

@dharkness
Copy link

Are you in the directory containing the test case? Do you have a bootstrap.php file that sets up the include path appropriately?

@hosseio
Copy link

hosseio commented Oct 19, 2011

Are you using "tab" for complete the address to the file? if you are doing that stop doing it, write the address manually :)

@edorian
Copy link
Sponsor Contributor

edorian commented Nov 10, 2011

Seems more like a file permission or some other kind of error than a phpunit problem. As I've got no way of reproducing this I'll close it. Feel free to reopen if needed

@edorian edorian closed this as completed Nov 10, 2011
@alfetopito
Copy link

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 :/

@Lechus
Copy link

Lechus commented Aug 2, 2012

Thx alfetopito!

@alanwillms
Copy link

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).

@chitwarnold
Copy link

i had the same problem, the its was a path issue, kindly check that you are pointing your bash terminal to the correct path.

@profnandaa
Copy link

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

@spidgorny
Copy link

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

@pumamammal
Copy link

I have been trying to install PHPunit for 5days!. now its working and am having this error which might be the last I will have.

I am geting "cannot open file filename.php"

please help!!

@sebastianbergmann
Copy link
Owner

@pumamammal I would like to understand why it took you five days to install PHPUnit as I would like to improve the documentation accordingly. Can you please open a ticket at https://github.com/sebastianbergmann/phpunit-documentation/issues/new and explain where https://phpunit.de/getting-started.html and https://phpunit.de/manual/current/en/installation.html failed you?

As for your cannot open file filename.php issue, @pumamammal, please understand that I can only make sense of complete output and not just random snippets, sorry.

@bpfruin
Copy link

bpfruin commented May 18, 2016

I'm having the same error too after working through a few other nasty ones. I've been at this for 5 days nonstop as well. Safe mode is off, permissions are 777. I don't have a bootstrap.php file. Is that necessary? If so, is there any documentation on how to create one? I'm a novice developer.

@poldiwa
Copy link

poldiwa commented Jun 23, 2016

I'm getting same error too, but when I don't specify a file it run with no problem.
I'm a newbie too.
PHPUnit 5.4.6, installed via Composer 1.1.2, Windows 10 64 bit.

@lingeors
Copy link

lingeors commented Aug 7, 2016

I'm getting the same error too, and I try to solve it through the following steps

  • require the autoload.php file
  • I try to using the command "phpunit myFile.php", adding ".php"
    and it work. though I know nothing.
    phpunit 5.5.0, windows 10 64 bit, php5.6

@mboo2005
Copy link

I solved the problem!!
Correct syntax: phpunit tests/PagesTest .
Inspired by https://phpunit.de/manual/current/en/organizing-tests.html#organizing-tests.filesystem

Thank you

@AnderSouza
Copy link

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. :D

4d47 added a commit to 4d47/php-archieml that referenced this issue Dec 11, 2017
see: sebastianbergmann/phpunit#279

Somehow have the issue on local Solus but not on Travis.
@terdia
Copy link

terdia commented Mar 21, 2018

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

@Goahnary
Copy link

Goahnary commented Apr 15, 2019

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

@JustAWebDev
Copy link

Same for me. Simply adding the "--filter" flag worked. Otherwise it didn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests