Slim-Skeleton: logs folder messes up unit tests

Initially all tests (from “tests/Functional”) work (green, OK).

But the framework throws in an error: “… directory … logs is not accessible”.
Ok, so I chmod it, and the app starts to work, but two of the tests start to fail:

Tests\Functional\HomepageTest::testGetHomepageWithoutName
Failed asserting that 500 matches expected 200.

Omg, why is that?

I found this because I was having the same problem, so glad to find the question, but disappointed that there was no answer! So, for the next person in my shoes, here’s what I figured out:

The problem isn’t the permissions on the logs/ directory. That does need to be writable. But so does the app.log file inside of that directory. In my case (and yours, I’m guessing) I ran my web version using apache, but my tests (on the command line) run as my user. As such, you need to make sure that logs/ and logs/app.log are both writable by the username running the tests and the username of your web server process (in my case (Linux Mint 18), www-data). If you go with the default, then whoever “gets there first” will own the app.log file. That is, if you run a test before opening the app in your browser, then app.log will be writable for tests but not web hits. If you start with your browser, then the tests will fail.

So… do one; then chmod (or chown); and then confirm that you can do the other. For instance:

# right now the logs/ dir should be writable, but there's no app.log file yet
php composer.phar test
# now logs/app.log exists and is owned by the logged-in user
# web hits will cause errors because the apache user can't write to the log file
chmod 777 logs/app.log
# now it should work
links http://localhost/slimskel/

1 Like