0

I'm upgrading a laravel 3 site to laravel 4, and writing unit tests for it as I go. This is working great, I've about 300 tests so far in about 20 test cases, and each one of them work fine run individually. Until recently they have all worked fine run together, but I seem to have crossed some threshold where I can't run any more tests in one go without the following error:

PHP Fatal error:  Illuminate\Filesystem\Filesystem::getRequire(): Failed opening required '/Users/Me/Desktop/Repos/API-2/app/config/api.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.4/lib/php') in /Users/Me/Desktop/Repos/API-2/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 53

The config file which is failing to include is used in almost every single test, and as ALL test cases work fine when run individually, I can't understand why this error is happening only when they are all run together.

This error shows when the tests near completion, so my first though was a memory or execution time limit, I've tried doubling these in php.ini, but I don't think they apply in the CLI anyway? I'm not sure what else could cause a problem like this which only happens when all are run together?

Edit

Does no one know what could be causing this? Currently the best I can do for now to run all the tests is the following bash script, then scroll though the pages of result looking for errors...

#!/bin/bash
for f in app/tests/*Test.php ; do phpunit "$f" ; done
Malcolm Christie
  • 727
  • 1
  • 6
  • 20
  • Have you tried using the `--process-isolation` option? http://phpunit.de/manual/3.7/en/textui.html – SamV Dec 17 '13 at 10:47
  • I assume I'd just execute `phpunit --process-isolation`? I'm not sure if I'm doing it wrong as every single test fails when I do it that way :/ `Constant LARAVEL_START already defined` – Malcolm Christie Dec 17 '13 at 10:51
  • Edit `phpunit.xml` in the project directory and set the value to `true`. – SamV Dec 17 '13 at 10:51
  • Unfortunately I get the same error on every test when I do it that way too. – Malcolm Christie Dec 17 '13 at 10:56
  • Just a quick one, are you 100% certain it's api.php not app.php you're looking for? – ollieread Dec 17 '13 at 11:29
  • Yip it's not app.php, it's a config file I have called api.php (it's an API I'm making). – Malcolm Christie Dec 17 '13 at 15:06
  • Can you show us the source code where the `api.php` file is requested ? I know you are not simply using `require('api.php')`, so I want to see how you are doing it. – Alexandre Danault Jan 06 '14 at 14:37
  • It's being included by the laravel framework `/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 53`, it's a config file so the only way I'm ever accessing it is with `Config::get('api.foo.bar')` – Malcolm Christie Jan 06 '14 at 15:01
  • `Config::get('api.foo.bar')` is what I wated to know, thanks. Does the PHP error log give any more details about the failed include/require, like a reason or an error code ? – Alexandre Danault Jan 06 '14 at 20:03
  • Nope, I've just rerun phpunit, had the error, but the last error in the log is a mistake I made yesterday.Incidentally, now that I've changed and added tests the error has changed slightly, it's still a require problem but in a different place `PHP Fatal error: TestCase::createApplication(): Failed opening required '/Users/Malk/Desktop/Repos/Miituu-API-2/app/tests/../../bootstrap/start.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.4/lib/php') in /Users/Malk/Desktop/Repos/Miituu-API-2/app/tests/TestCase.php on line 144` – Malcolm Christie Jan 07 '14 at 09:00

1 Answers1

3

Assuming this is on a *nix based system, this sounds a lot like a ulimit issue (open files limit).

Check the output of ulimit -n and ulimit -Hn for the soft and hard open files limit, respectively. If it is something ridiculously small, like 1024, you may want to up it.

See: How do I change the number of open files limit in Linux?

Also be aware that these limits are per-user, not global, so make sure to run this as the user that runs the unit tests.

Edit: Fixed by errant.info's answer here: https://superuser.com/questions/302754/increase-the-maximum-number-of-open-file-descriptors-in-snow-leopard because MacOSX is... special.

Community
  • 1
  • 1
Tasos Bitsios
  • 2,699
  • 1
  • 16
  • 22
  • Thanks Tasos, this is on a Mac, but when I run `ulimit -n` and `ulimit -Hn` they both return `unlimited`, so it looks like that's not the issue unfortunately? – Malcolm Christie Jan 08 '14 at 08:55
  • Just to double-check, you ran this as Malk - same user that runs the unit tests? – Tasos Bitsios Jan 08 '14 at 09:24
  • I think I found something else. MacOSX is... special. On mine, (10.6/64bit) `ulimit -n` says 2560, whereas `launchctl limit maxfiles` says 256|unlimited. Not sure which one it is obeying, but worth a shot. This really, really sounds like an open files limit. Can you check the output of: `launchctl limit`? Look for the maxfiles line, if they aren't both unlimited, set with `launchctl limit maxfiles unlimited unlimited` (or a high value if it doesn't let you do that) – Tasos Bitsios Jan 08 '14 at 09:33
  • Yip, I'm running all this as Malk. `launchctl limit` says that `maxfiles 256 unlimited`, I tried changing it to unlimited but it needed an int for both so I changed them both to 4096, but get the same error around the same place :( I also can't change the second value back to unlimited, even with sudo :/ – Malcolm Christie Jan 08 '14 at 10:12
  • One more hoop for you to jump through: can you try the answer by errant.info on this question: http://superuser.com/questions/302754/increase-the-maximum-number-of-open-file-descriptors-in-snow-leopard and try again after a reboot? (also backup any files changed) If that doesn't work either, I have no more ideas, sorry. – Tasos Bitsios Jan 08 '14 at 11:25
  • Do you have zenddebugger? http://stackoverflow.com/questions/19766745/apache-php-osx-mavericks-failed-to-open-stream-too-many-open-files – Tasos Bitsios Jan 08 '14 at 11:32
  • Yes! That's sorted it! Thanks very much, this has been driving me mad for so long, fantastic to have a solution! :D – Malcolm Christie Jan 08 '14 at 11:48
  • Just for the record, it was Errant.info's answer that worked, right? Not the zenddebugger thing? – Tasos Bitsios Jan 08 '14 at 11:52
  • Yes, the answer from errant.info on http://superuser.com/questions/302754/increase-the-maximum-number-of-open-file-descriptors-in-snow-leopard – Malcolm Christie Jan 08 '14 at 12:30