Skip to content

Commit 0718d9c

Browse files
committed
Merge branch 'peter279k-master'
2 parents feb971d + 89a2748 commit 0718d9c

File tree

3 files changed

+85
-25
lines changed

3 files changed

+85
-25
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"phpmd": "vendor/bin/phpmd src,tests text ./phpmd.xml",
5656
"fix": [
5757
"vendor/bin/php-cs-fixer fix -v",
58-
"vendor/bin/phpcbf src,tests"
58+
"vendor/bin/phpcbf src tests"
5959
],
6060
"tests": [
6161
"clear",

src/Session.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ public static function setPrefix($prefix)
5050
return is_string(self::$prefix = $prefix);
5151
}
5252

53+
/**
54+
* Get prefix for sessions.
55+
*
56+
* @since 1.0.0
57+
*
58+
* @return string
59+
*/
60+
public static function getPrefix()
61+
{
62+
return self::$prefix;
63+
}
64+
5365
/**
5466
* If session has not started, start sessions.
5567
*

tests/SessionTest.php

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function setUp()
4848
public function testIsInstanceOfSession()
4949
{
5050
$actual = $this->Session;
51+
5152
$this->assertInstanceOf('Josantonius\Session\Session', $actual);
5253
}
5354

@@ -58,7 +59,22 @@ public function testIsInstanceOfSession()
5859
*/
5960
public function testSetPrefix()
6061
{
61-
$this->assertTrue($this->Session->setPrefix('ses_'));
62+
$session = $this->Session;
63+
64+
$this->assertTrue($session::setPrefix('ses_'));
65+
}
66+
67+
/**
68+
* Get prefix for sessions.
69+
*
70+
* @since 1.1.3
71+
*/
72+
public function testGetPrefix()
73+
{
74+
$session = $this->Session;
75+
$session::setPrefix('ses_');
76+
77+
$this->assertSame('ses_', $session::getPrefix());
6278
}
6379

6480
/**
@@ -70,7 +86,10 @@ public function testSetPrefix()
7086
*/
7187
public function testInit()
7288
{
73-
$this->assertTrue($this->Session->init());
89+
$session = $this->Session;
90+
91+
$this->assertTrue($session::init());
92+
$this->assertFalse($session::init());
7493
}
7594

7695
/**
@@ -80,7 +99,9 @@ public function testInit()
8099
*/
81100
public function testSet()
82101
{
83-
$this->assertTrue($this->Session->set('name', 'Joseph'));
102+
$session = $this->Session;
103+
104+
$this->assertTrue($session::set('name', 'Joseph'));
84105
}
85106

86107
/**
@@ -90,13 +111,14 @@ public function testSet()
90111
*/
91112
public function testSetMultiple()
92113
{
114+
$session = $this->Session;
93115
$data = [
94116
'name' => 'Joseph',
95117
'age' => '28',
96118
'business' => ['name' => 'Company'],
97119
];
98120

99-
$this->assertTrue($this->Session->set($data));
121+
$this->assertTrue($session::set($data));
100122
}
101123

102124
/**
@@ -106,7 +128,9 @@ public function testSetMultiple()
106128
*/
107129
public function testPull()
108130
{
109-
$this->assertContains('28', $this->Session->pull('age'));
131+
$session = $this->Session;
132+
133+
$this->assertContains('28', $session::pull('age'));
110134
}
111135

112136
/**
@@ -116,7 +140,9 @@ public function testPull()
116140
*/
117141
public function testPullNonExistent()
118142
{
119-
$this->assertNull($this->Session->pull('???'));
143+
$session = $this->Session;
144+
145+
$this->assertNull($session::pull('???'));
120146
}
121147

122148
/**
@@ -126,7 +152,9 @@ public function testPullNonExistent()
126152
*/
127153
public function testGet()
128154
{
129-
$this->assertContains('Joseph', $this->Session->get('name'));
155+
$session = $this->Session;
156+
157+
$this->assertContains('Joseph', $session::get('name'));
130158
}
131159

132160
/**
@@ -136,7 +164,9 @@ public function testGet()
136164
*/
137165
public function testGetNonExistent()
138166
{
139-
$this->assertNull($this->Session->get('age'));
167+
$session = $this->Session;
168+
169+
$this->assertNull($session::get('age'));
140170
}
141171

142172
/**
@@ -146,7 +176,9 @@ public function testGetNonExistent()
146176
*/
147177
public function testGetWithSecondKey()
148178
{
149-
$this->assertContains('Company', $this->Session->get('business', 'name'));
179+
$session = $this->Session;
180+
181+
$this->assertContains('Company', $session::get('business', 'name'));
150182
}
151183

152184
/**
@@ -156,7 +188,9 @@ public function testGetWithSecondKey()
156188
*/
157189
public function testGetWithSecondKeyNonExistent()
158190
{
159-
$this->assertNull($this->Session->get('???', '???'));
191+
$session = $this->Session;
192+
193+
$this->assertNull($session::get('???', '???'));
160194
}
161195

162196
/**
@@ -166,7 +200,9 @@ public function testGetWithSecondKeyNonExistent()
166200
*/
167201
public function testGetAll()
168202
{
169-
$this->assertInternalType('array', $this->Session->get());
203+
$session = $this->Session;
204+
205+
$this->assertInternalType('array', $session::get());
170206
}
171207

172208
/**
@@ -176,7 +212,9 @@ public function testGetAll()
176212
*/
177213
public function testId()
178214
{
179-
$this->assertInternalType('string', $this->Session->id());
215+
$session = $this->Session;
216+
217+
$this->assertInternalType('string', $session::id());
180218
}
181219

182220
/**
@@ -188,9 +226,11 @@ public function testId()
188226
*/
189227
public function testRegenerate()
190228
{
191-
$this->assertTrue($this->Session->init());
229+
$session = $this->Session;
230+
231+
$this->assertTrue($session::init());
192232

193-
$this->assertInternalType('string', $this->Session->regenerate());
233+
$this->assertInternalType('string', $session::regenerate());
194234
}
195235

196236
/**
@@ -202,13 +242,15 @@ public function testRegenerate()
202242
*/
203243
public function testValidateRegenerateId()
204244
{
205-
$this->assertTrue($this->Session->init());
245+
$session = $this->Session;
246+
247+
$this->assertTrue($session::init());
206248

207-
$actualID = $this->Session->id();
249+
$actualID = $session::id();
208250

209251
$this->assertInternalType('string', $actualID);
210252

211-
$newID = $this->Session->regenerate();
253+
$newID = $session::regenerate();
212254

213255
$this->assertInternalType('string', $newID);
214256

@@ -224,18 +266,24 @@ public function testValidateRegenerateId()
224266
*/
225267
public function testDestroy()
226268
{
227-
$this->assertTrue($this->Session->init());
269+
$session = $this->Session;
270+
271+
$this->assertTrue($session::init());
272+
273+
$this->assertTrue($session::set('name', 'Joseph'));
274+
275+
$this->assertContains('Joseph', $session::get('name'));
228276

229-
$this->assertTrue($this->Session->set('name', 'Joseph'));
277+
$this->assertTrue($session::destroy('name'));
230278

231-
$this->assertContains('Joseph', $this->Session->get('name'));
279+
$this->assertNull($session::get('name'));
232280

233-
$this->assertTrue($this->Session->destroy('name'));
281+
$this->assertTrue($session::destroy('ses_', true));
234282

235-
$this->assertNull($this->Session->get('name'));
283+
$this->assertTrue($session::set('name', 'Joseph'));
236284

237-
$this->assertTrue($this->Session->destroy('ses_', true));
285+
$this->assertTrue($session::destroy('name', true));
238286

239-
$this->assertTrue($this->Session->destroy());
287+
$this->assertTrue($session::destroy());
240288
}
241289
}

0 commit comments

Comments
 (0)