Skip to content

Commit c9ae155

Browse files
committed
Added dontSeeInSession and dontSeeSessionHasValues methods
1 parent 800093d commit c9ae155

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/Codeception/Module/Laravel/InteractsWithSession.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,57 @@
66

77
trait InteractsWithSession
88
{
9+
/**
10+
* Assert that a session attribute does not exist, or is not equal to the passed value.
11+
*
12+
* ```php
13+
* <?php
14+
* $I->dontSeeInSession('attribute');
15+
* $I->dontSeeInSession('attribute', 'value');
16+
* ```
17+
*
18+
* @param string|array $key
19+
* @param mixed|null $value
20+
*/
21+
public function dontSeeInSession($key, $value = null): void
22+
{
23+
if (is_array($key)) {
24+
$this->dontSeeSessionHasValues($key);
25+
return;
26+
}
27+
28+
$session = $this->getSession();
29+
30+
if (null === $value) {
31+
if ($session->has($key)) {
32+
$this->fail("Session variable with key '{$key}' does exist");
33+
}
34+
}
35+
else {
36+
$this->assertNotSame($value, $session->get($key));
37+
}
38+
}
39+
40+
/**
41+
* Assert that the session does not have a particular list of values.
42+
*
43+
* ```php
44+
* <?php
45+
* $I->dontSeeSessionHasValues(['key1', 'key2']);
46+
* $I->dontSeeSessionHasValues(['key1' => 'value1', 'key2' => 'value2']);
47+
* ```
48+
*/
49+
public function dontSeeSessionHasValues(array $bindings): void
50+
{
51+
foreach ($bindings as $key => $value) {
52+
if (is_int($key)) {
53+
$this->dontSeeInSession($value);
54+
} else {
55+
$this->dontSeeInSession($key, $value);
56+
}
57+
}
58+
}
59+
960
/**
1061
* Flush all of the current session data.
1162
*/

0 commit comments

Comments
 (0)