CookieTest.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Utils;
  4. use PHPUnit\Framework\TestCase;
  5. use App\Utils\Cookie;
  6. final class CookieTest extends TestCase
  7. {
  8. /**
  9. * @covers App\Utils\Cookie::set
  10. */
  11. public function testSet(): void
  12. {
  13. $data = ['testKey' => 'testValue'];
  14. $time = time() + 3600;
  15. Cookie::set($data, $time);
  16. $this->assertEquals('testValue', $_COOKIE['testKey']);
  17. }
  18. /**
  19. * @covers App\Utils\Cookie::setWithDomain
  20. */
  21. public function testSetWithDomain(): void
  22. {
  23. $data = ['testKey' => 'testValue'];
  24. $time = time() + 3600;
  25. $domain = 'localhost';
  26. Cookie::setWithDomain($data, $time, $domain);
  27. $this->assertEquals('testValue', $_COOKIE['testKey']);
  28. }
  29. /**
  30. * @covers App\Utils\Cookie::get
  31. */
  32. public function testGet(): void
  33. {
  34. $data = ['testKey' => 'testValue'];
  35. $time = time() + 3600;
  36. Cookie::set($data, $time);
  37. $this->assertEquals('testValue', Cookie::get('testKey'));
  38. }
  39. }