| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace Test\Michel\Session;
- use Michel\Session\Storage\NativeSessionStorage;
- use Michel\UniTester\TestCase;
- final class NativeSessionTest extends TestCase
- {
- protected function setUp(): void
- {
- $_SESSION = [];
- }
- protected function tearDown(): void
- {
- $_SESSION = [];
- session_destroy();
- }
- protected function execute(): void
- {
- $this->expectException(\RuntimeException::class, function () {
- new NativeSessionStorage([
- 'save_path' => '/tmp/testnotfound',
- ]);
- });
- $session = new NativeSessionStorage();
- $session['username'] = 'myName';
- $this->assertTrue($session->has('username'));
- $session['role'] = 'ADMIN';
- $this->assertTrue($session->has('role'));
- $this->assertStrictEquals('myName', $session->get('username'));
- $article = [
- 'title' => 'TV',
- 'description' => 'lorem',
- 'price' => 199.80
- ];
- $session->put('article',$article);
- $this->assertStrictEquals($article, $session->get('article'));
- $this->assertTrue(is_float($session->get('article')['price']));
- $this->assertTrue(count($session->all()) === 3);
- $this->assertStrictEquals(null, $session->get('email'));
- $this->assertStrictEquals('dev@phpdevcommunity.com', $session->get('email', 'dev@phpdevcommunity.com'));
- }
- }
|