CookieTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Cookie Utils tests using Pest
  4. */
  5. use App\Utils\Cookie;
  6. describe('Cookie::set', function () {
  7. it('accepts correct parameters without throwing error', function () {
  8. $data = ['testKey' => 'testValue'];
  9. $time = time() + 3600;
  10. // In CLI environment, we can't test setcookie directly
  11. // Instead, we verify the method accepts correct parameters
  12. // If this doesn't throw an error, the method signature is correct
  13. expect(fn() => Cookie::set($data, $time))->not->toThrow(\Exception::class);
  14. });
  15. });
  16. describe('Cookie::setWithDomain', function () {
  17. it('accepts correct parameters with domain without throwing error', function () {
  18. $data = ['testKey' => 'testValue'];
  19. $time = time() + 3600;
  20. $domain = 'localhost';
  21. // In CLI environment, we can't test setcookie directly
  22. // Instead, we verify the method accepts correct parameters
  23. expect(fn() => Cookie::setWithDomain($data, $time, $domain))->not->toThrow(\Exception::class);
  24. });
  25. });
  26. describe('Cookie::get', function () {
  27. it('retrieves cookie value from $_COOKIE superglobal', function () {
  28. // Test get method by directly setting $_COOKIE
  29. $_COOKIE['testKey'] = 'testValue';
  30. expect(Cookie::get('testKey'))->toBe('testValue');
  31. // Clean up
  32. unset($_COOKIE['testKey']);
  33. });
  34. it('returns empty string for non-existent key', function () {
  35. expect(Cookie::get('nonExistentKey'))->toBe('');
  36. });
  37. });