Weird interaction with behat & phpunit

I’ve been building a PHP project that tests with Behat with no problem. I’ve added PHPUnit tests as well and now I can’t build successfully.

When I run only the behat tests, everything is fine, a log file gets written, and it’s all good.

When I run PHPUnit alone, everything is fine, a log file gets written, and it’s all good.

When I run behat then PHPUnit, the PHPUnit tests all fail because:

The stream or file “/home/ubuntu/iys/storage/logs/laravel.log” could not be opened: failed to open stream: Permission denied

But this is after successfully writing to the laravel.log file when behat runs.

I’m not aware of any interaction between the two frameworks that should prevent things from running. What am I doing wrong?

Here’s some relevant bits of my circle.yml file:

  pre:
     - cp ~/iys/build/circle.env ~/iys/.env
     - sudo chmod -R 777 storage

## Customize test commands
test:
  pre:
  ## reset the test database
    - php artisan test:refresh
  override:
    - php vendor/bin/behat -c"behat.yml" # and a little behat too
    - phpunit tests # use PHPunit for testing
  post:
    - cp ~/iys/storage/logs/*.* $CIRCLE_ARTIFACTS
    - cp /var/log/apache2/*.log $CIRCLE_ARTIFACTS