Skip to content

Commit 1504e65

Browse files
TavoNiievezNaktibalda
authored andcommitted
Added seeInSession function
1 parent 5ac2186 commit 1504e65

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

documentation.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,21 @@ $I->seeInFormFields('//form[@id=my-form]', $form);
11011101
* `param` $params
11021102

11031103

1104+
### seeInSession
1105+
1106+
Assert that a session attribute exists.
1107+
1108+
```php
1109+
<?php
1110+
$I->seeInSession('attrib');
1111+
$I->seeInSession('attrib', 'value');
1112+
```
1113+
1114+
* `param string` $attrib
1115+
* `param mixed|null` $value
1116+
* `return` void
1117+
1118+
11041119
### seeInSource
11051120

11061121
Checks that the current page contains the given string in its

src/Codeception/Module/Symfony.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,38 @@ public function logout()
845845
}
846846
}
847847
$cookieJar->flushExpiredCookies();
848+
}
849+
850+
/**
851+
* Assert that a session attribute exists.
852+
*
853+
* ```php
854+
* <?php
855+
* $I->seeInSession('attrib');
856+
* $I->seeInSession('attrib', 'value');
857+
* ```
858+
*
859+
* @param string $attrib
860+
* @param mixed|null $value
861+
* @return void
862+
*/
863+
public function seeInSession($attrib, $value = null)
864+
{
865+
$container = $this->_getContainer();
848866

867+
if (!$container->has('session')) {
868+
$this->fail("Symfony container doesn't have 'session' service");
869+
return;
870+
}
871+
872+
$session = $this->grabService('session');
873+
874+
if (! $session->has($attrib)) {
875+
$this->fail("No session attribute with name '$attrib'");
876+
}
877+
878+
if (null !== $value) {
879+
$this->assertEquals($value, $session->get($attrib));
880+
}
849881
}
850882
}

0 commit comments

Comments
 (0)