Skip to content

Commit cc033be

Browse files
committed
test flash
1 parent 0cc5fce commit cc033be

2 files changed

Lines changed: 85 additions & 5 deletions

File tree

‎src/Session.php‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,15 @@ public static function destroy(): void
194194
/**
195195
* @return bool
196196
*/
197-
public static function abort(): bool
197+
public static function commit(): void
198+
{
199+
session_commit();
200+
}
201+
202+
/**
203+
* @return bool
204+
*/
205+
public static function rollback(): bool
198206
{
199207
return session_abort();
200208
}
@@ -228,6 +236,16 @@ protected static function startSessionIfNotHasStartedForceWrite()
228236
}
229237
}
230238

239+
public static function setReadOnly()
240+
{
241+
static::$options['read_and_close'] = true;
242+
}
243+
244+
public static function setReadWrite()
245+
{
246+
static::$options['read_and_close'] = false;
247+
}
248+
231249
/**
232250
* @throws Exception
233251
*

‎tests/SessionTest.php‎

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public function testRemove()
101101
public function testStartException()
102102
{
103103
static::expectException(Exception::class);
104-
Session::start(['read_and_write' => false]);
104+
Session::setReadWrite();
105+
Session::start();
105106
Session::start();
106107
}
107108

@@ -111,7 +112,8 @@ public function testStartException()
111112
public function testUseDefaultDriverWhenAlreadyStartedException()
112113
{
113114
static::expectException(Exception::class);
114-
Session::start(['read_and_write' => false]);
115+
Session::setReadWrite();
116+
Session::start();
115117
Session::useDefaultDriver();
116118
}
117119

@@ -121,7 +123,8 @@ public function testUseDefaultDriverWhenAlreadyStartedException()
121123
public function testUseFileDriverWhenAlreadyStartedException()
122124
{
123125
static::expectException(Exception::class);
124-
Session::start(['read_and_write' => false]);
126+
Session::setReadWrite();
127+
Session::start();
125128
Session::useFileDriver();
126129
}
127130

@@ -131,7 +134,8 @@ public function testUseFileDriverWhenAlreadyStartedException()
131134
public function testUseCustomDriverWhenAlreadyStartedException()
132135
{
133136
static::expectException(Exception::class);
134-
Session::start(['read_and_write' => false]);
137+
Session::setReadWrite();
138+
Session::start();
135139
Session::useCustomDriver(new File());
136140
}
137141

@@ -340,4 +344,62 @@ public function testUseEncryptionDriverThrowExceptionWhenMethodIncrorrect()
340344
}
341345

342346
//exception quand methode pas bonne dans les encryption
347+
348+
/**
349+
* @runInSeparateProcess
350+
*/
351+
public function testSetOption()
352+
{
353+
$defaultOption = Session::getOption('name');
354+
static::assertEquals($defaultOption, ini_get('session.name'));
355+
356+
Session::setOption('name', 'my_custom_name');
357+
$customOption = Session::getOption('name');
358+
359+
static::assertEquals('my_custom_name', $customOption);
360+
361+
Session::start(['name' => 'my_other_name']);
362+
363+
$customOption = Session::getOption('name');
364+
static::assertEquals('my_other_name', $customOption);
365+
}
366+
367+
/**
368+
* @runInSeparateProcess
369+
*/
370+
public function testSetOptionThrowException()
371+
{
372+
static::expectException(Exception::class);
373+
Session::getOption('azerty');
374+
}
375+
376+
/**
377+
* @runInSeparateProcess
378+
*/
379+
public function testGetAll()
380+
{
381+
$sessionValues = Session::getAll();
382+
static::assertTrue(empty($sessionValues));
383+
384+
Session::set('a', 'b');
385+
386+
$sessionValues = Session::getAll();
387+
static::assertEquals(['a' => 'b'], $sessionValues);
388+
}
389+
390+
/**
391+
* @runInSeparateProcess
392+
*/
393+
public function testFlash()
394+
{
395+
Session::setFlash('a', 'b');
396+
Session::setFlash('y', 'u');
397+
static::assertTrue(Session::hasFlash('a'));
398+
static::assertEquals('b', Session::getFlash('a'));
399+
Session::start(['lazy_write' => '0']);
400+
Session::keepFlash(['y']);
401+
static::assertEquals(['flash_data' => 'u'], $_SESSION);
402+
Session::commit();
403+
session_start();
404+
}
343405
}

0 commit comments

Comments
 (0)