PHP built in server and sessions

Hi!

Today I was struggling with Codeception tests. I’m working on Vagrant machine which has Apache2 installed.

Thing is that to view the page on my host machine I’m utilising Apache. But in the acceptance tests I’m using PHP built in server. To be specific https://github.com/tiger-seo/PhpBuiltinServer is used. It allows to run server as tests are running and destroy it at the end. It also supports many options.

Acceptance tests were broken. The Tester could not login. After some investigation I found that the issue was caused by read/write permissions for session. By default my Vagrant tries to store the session files in the /var/lib/php/session. As I opened my project in Apache earlier the permissions were given for it. There are two options to solve this:

  • change the path for session files,
  • change the permissions for the current path.

I choose first option. To be specific I changed it only for server used by tests. The extension allows to specify custom .ini file. So my file tests/php.ini look like this:

date.timezone="Europe/London"
session.save_path="/tmp"

Also here’s part of my codeception.yml file:

extensions:
    enabled:
        - Codeception\Extension\PhpBuiltinServer
    config:
        Codeception\Extension\PhpBuiltinServer:
            hostname: localhost
            port: 8000
            documentRoot: .
            phpIni: tests/php.ini
            startDelay: 0

Now session are working in tests 🙂

 

Cheers!