2
0

NativeSessionTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Test\Michel\Session;
  3. use Michel\Session\Storage\NativeSessionStorage;
  4. use Michel\UniTester\TestCase;
  5. final class NativeSessionTest extends TestCase
  6. {
  7. protected function setUp(): void
  8. {
  9. $_SESSION = [];
  10. }
  11. protected function tearDown(): void
  12. {
  13. $_SESSION = [];
  14. session_destroy();
  15. }
  16. protected function execute(): void
  17. {
  18. $this->expectException(\RuntimeException::class, function () {
  19. new NativeSessionStorage([
  20. 'save_path' => '/tmp/testnotfound',
  21. ]);
  22. });
  23. $session = new NativeSessionStorage();
  24. $session['username'] = 'myName';
  25. $this->assertTrue($session->has('username'));
  26. $session['role'] = 'ADMIN';
  27. $this->assertTrue($session->has('role'));
  28. $this->assertStrictEquals('myName', $session->get('username'));
  29. $article = [
  30. 'title' => 'TV',
  31. 'description' => 'lorem',
  32. 'price' => 199.80
  33. ];
  34. $session->put('article',$article);
  35. $this->assertStrictEquals($article, $session->get('article'));
  36. $this->assertTrue(is_float($session->get('article')['price']));
  37. $this->assertTrue(count($session->all()) === 3);
  38. $this->assertStrictEquals(null, $session->get('email'));
  39. $this->assertStrictEquals('dev@phpdevcommunity.com', $session->get('email', 'dev@phpdevcommunity.com'));
  40. }
  41. }