Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,21 @@ $I->seeInFormFields('//form[@id=my-form]', $form);
* `param` $params


### seeInSession

Assert that a session attribute exists.

```php
<?php
$I->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
Expand Down
33 changes: 33 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,37 @@ private function getPossibleKernelClasses()

return [$this->config['kernel_class']];
}

/**
* Assert that a session attribute exists.
*
* ```php
* <?php
* $I->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));
}
}
}