From 8765387b33d76e5342f28e272b0f07c80afed0df Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Thu, 10 Sep 2020 20:03:36 -0500 Subject: [PATCH 1/2] Added seeInSession function --- documentation.md | 15 ++++++++++++++ src/Codeception/Module/Symfony.php | 32 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) 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..96f55093 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -770,4 +770,36 @@ 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')) { + 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)); + } + } } From c3a171c8fffcd411b6c36db9d4f631cc6e9ddde3 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Fri, 11 Sep 2020 22:00:39 -0500 Subject: [PATCH 2/2] fails if you don't have the necessary services --- src/Codeception/Module/Symfony.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 96f55093..22f2edb6 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -789,6 +789,7 @@ public function seeInSession($attrib, $value = null) $container = $this->_getContainer(); if (!$container->has('session')) { + $this->fail("Symfony container doesn't have 'session' service"); return; }