Using Sessions in PHPUnit Tests with CakePHP

I was breaking my head over failing unit tests when trying to test a simple Controller that was saving a new record. Turned out it was failing only on the command line, while the webversion was passing all the tests. Luckily, the solution was simple .. The PHPUnit command line suite apparently outputs contents early, before the session gets initiated. Solution 1 Add --stderr to the command line: $ cake testsuite app Controller/YourFancyController --stderr This will pass the tests again, as it doesn’t output contents early to STDOUT.