forked from cakephp/codeception
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionTrait.php
More file actions
75 lines (65 loc) · 1.94 KB
/
Copy pathSessionTrait.php
File metadata and controls
75 lines (65 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Cake\Codeception\Helper;
trait SessionTrait
{
/**
* Inserts key/value(s) in the session.
*
* @param string|array $key Session key or array of key/values.
* @param mixed $value Value.
*/
public function haveInSession($key, $value = null)
{
$this->grabService('session')->write($key, $value);
}
/**
* Asserts that given key (and value) exist in the session.
*
* @param string|array $key Session key or array of key/values.
* @param mixed $value Value to check for. If `NULL`, check only key.
*/
public function seeInSession($key, $value = null)
{
if (is_array($key)) {
array_walk($key, function ($v, $k) {
if (is_int($k)) {
$k = $v;
$v = null;
}
$this->seeInSession($k, $v);
});
return;
}
$session = $this->grabService('session');
if (is_null($value)) {
$this->assertTrue($session->check($key));
return;
}
$this->assertEquals($value, $session->read($key));
}
/**
* Asserts that given key (and value) do not exist in the session.
*
* @param string|array $key Session key or array of key/values.
* @param mixed $value Value to check for. If `NULL`, check only key.
*/
public function dontSeeInSession($key, $value = null)
{
if (is_array($key)) {
array_walk($key, function ($v, $k) {
if (is_int($k)) {
$k = $v;
$v = null;
}
$this->dontSeeInSession($k, $v);
});
return;
}
$session = $this->grabService('session');
if (is_null($value)) {
$this->assertFalse($session->check($key));
return;
}
$this->assertNotEquals($value, $session->read($key));
}
}