I am building an application in Silex with unit tests.
Running unit tests works fine with a regular session handler:
$app->register(new Silex\Provider\SessionServiceProvider(), array( 'session.storage.options' => array( 'cookie_lifetime' => 1209600,
and setting this flag in my unit tests:
$this->app['session.test'] = true;
If I do not set this session.test flag, my unit tests throw headers, errors already posted, and all fail. However, my tests pass well.
The problem is that I am trying to use the flashBag function (session information that lasts only until the first request is deleted):
$foo = $app['session']->getFlashBag()->all();
FlashBag does not seem to respect the session.test flag and tries to send headers that cause all of my unit tests to fail:
24) Yumilicious \ UnitTests \ Validator \ PersonAccountTest :: setConstraintsPassesWithMinimumAttributes RuntimeException: The session could not be started because the headers have already been sent.
/webroot/yumilicious/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php:142 / webroot / yumilicious / vendor / symfony / http -foundation / Symfony / Component / HttpF /NativeSessionStorage.php:262 / webroot / yumilicious / vendor / symfony / http -foundation / Symfony / Component / HttpFoundation / Session / Session.php: 240 / webroot / yumilicious / vendor / symfony / http -foundation / Symfony / Component / HttpFoundation /Session/Session.php:250 /webroot/yumilicious/src/app.php:38 /webroot/yumilicious/tests/Yumilicious/UnitTests/Base.php:13 / webroot / yumilicious / vendor / silex / silex / src / Silex /WebTestCase.php:34 /webroot/yumilicious/vendor/EHER/PHPUnit/src/phpunit/phpunit.php:46 / Webroot / yumilicious / seller / Eher / PHPUnit / bin / PHPUnit: 5
I narrowed it down to this piece of code: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L259
In particular, line 262. Commenting that one line allows my tests to work correctly and everyone skips green.
I was looking quite a bit to get this to work, but I was out of luck. I think this is because the flashBag stuff is new (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Session.php#L305) and the old methods are deprecated.
Any suggestions that my unit tests work would be great.