Docker & PHPUnit in PHPStorm

Hi there.

I have a PHPStorm project running in a Docker container. Everything is setup nicely - it all 'works' well. I can step through (F8 etc.) regular execution (via xdebug) and I can also step through my PHPUnit tests when executing them via the Console (i.e. Mac, Ctrl+R).

However, some of my PHPUnit tests are failing when they should not be... where they are accessing files in the filesystem, outside of the project's main folder (i.e. not in /opt/project mapping). When stepping through, it seems that the unit test doesn't have 'permissions' (?) to see the folder. The parent folder is there, but when calling file_exists() on a file in a sub-directory, it returns false.

Running the unit tests 'vanilla' on the command line outside of PHPStorm (i.e. via bash on the Docker container) yields all passes on the same tests.

So this leads me to believe it is PHPStorm's implementation (and/or my IDE configuration) that is causing failing. I tried adding the local/remote folder mapping and it still didn't pass.

I hope someone can help me, as I love using PHPStorm to run the tests but at the moment it's giving me 'false negatives'.

Thanks,

Dan

----

PHPStorm 2017.2.4

Docker 17.09.0

macOS High Sierra 10.13.1

PHPUnit 5.6.2

PHP 7.1.11

0
2 comments

> where they are accessing files in the filesystem, outside of the project's main folder 

Could you please explicitly name paths to test that do pass and test that don't?

One thing to check is PhpStorm | Preferences | Languages & Frameworks | PHP > Docker container > ... - you can set volume bindings there. If some of your tests are in folders outside of a project - you might try to map them there.

0
Avatar
Permanently deleted user

Thanks Dmitry. Sorry, I don't think I was very clear when I wrote that. All tests are in the Project Root/tests (so would be in /opt/project/tests) and they all run fine.

Some tests are explicitly looking for files (business domain) that are outside of the main project repo: so the file being checked for would actually reside in $path = '/var/www/file_repo/images/signatures/5.png' So my test (when run inside PHPStorm) is doing file_exists($path) to see whether the User has a signature uploaded or not. file_exists() is returning false.

But it should be true.

When I run the tests in bash inside the container, it passes i.e. file_exists returns true for those calls. Same code, same tests, just executed via different method.

Project root: /var/www/project/

File repo: /var/www/file_repo/

Does that make sense?

One more odd thing: if I 'break in' to the test and use the Alt+F8 to Evaluate Expression, I can do file_exists on /var/www/file_repo and it returns true... so it can see the 'top-level' folder. But anything inside that folder it returns false. I was sure it was permissions, but the fact it can see file_repo folder (which is outside of my project folder) makes it weird.

By the way, I did try adding the local and remote paths to the file repo again (which I had tried before) but it makes no difference. It still cannot see those files.

0

Please sign in to leave a comment.