diff --git a/documentation.md b/documentation.md index a7cbf282..214e6258 100644 --- a/documentation.md +++ b/documentation.md @@ -1092,6 +1092,21 @@ $I->seeInFormFields('//form[@id=my-form]', $form); * `param` $params +### seeInSession + +Assert that a session attribute exists. + +```php +seeInSession('attrib'); +$I->seeInSession('attrib', 'value'); +``` + + * `param string` $attrib + * `param mixed|null` $value + * `return` void + + ### seeInSource Checks that the current page contains the given string in its diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 39756533..22f2edb6 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -770,4 +770,37 @@ private function getPossibleKernelClasses() return [$this->config['kernel_class']]; } + + /** + * Assert that a session attribute exists. + * + * ```php + * seeInSession('attrib'); + * $I->seeInSession('attrib', 'value'); + * ``` + * + * @param string $attrib + * @param mixed|null $value + * @return void + */ + public function seeInSession($attrib, $value = null) + { + $container = $this->_getContainer(); + + if (!$container->has('session')) { + $this->fail("Symfony container doesn't have 'session' service"); + return; + } + + $session = $this->grabService('session'); + + if (! $session->has($attrib)) { + $this->fail("No session attribute with name '$attrib'"); + } + + if (null !== $value) { + $this->assertEquals($value, $session->get($attrib)); + } + } }