Skip to content

Commit d3b75a6

Browse files
committed
Added haveInSession and flushSession methods
1 parent 15df459 commit d3b75a6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Codeception/Module/Laravel/InteractsWithSession.php

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

77
trait InteractsWithSession
88
{
9+
/**
10+
* Set the session to the given array.
11+
*/
12+
public function haveInSession(array $data): void
13+
{
14+
$this->startSession();
15+
16+
foreach ($data as $key => $value) {
17+
$this->getSession()->put($key, $value);
18+
}
19+
}
20+
921
/**
1022
* Assert that a session variable exists.
1123
*
@@ -55,4 +67,23 @@ public function seeSessionHasValues(array $bindings): void
5567
}
5668
}
5769
}
70+
71+
/**
72+
* Flush all of the current session data.
73+
*/
74+
public function flushSession(): void
75+
{
76+
$this->startSession();
77+
$this->getSession()->flush();
78+
}
79+
80+
/**
81+
* Start the session for the application.
82+
*/
83+
protected function startSession(): void
84+
{
85+
if (! $this->getSession()->isStarted()) {
86+
$this->getSession()->start();
87+
}
88+
}
5889
}

0 commit comments

Comments
 (0)