server_mocks.php 862 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * A set of 'mocks' that replace the PHP global functions to aid testing.
  4. */
  5. namespace Cake\Http;
  6. function headers_sent()
  7. {
  8. return isset($GLOBALS['mockedHeadersSent']) ? $GLOBALS['mockedHeadersSent'] : true;
  9. }
  10. function header($header)
  11. {
  12. $GLOBALS['mockedHeaders'][] = $header;
  13. }
  14. function setcookie($name, $value, $expire, $path = '', $domain = '', $secure = false, $httponly = false)
  15. {
  16. if (is_array($expire)) {
  17. if (array_key_exists('expires', $expire)) {
  18. $expire['expire'] = $expire['expires'];
  19. unset($expire['expires']);
  20. }
  21. $GLOBALS['mockedCookies'][] = compact('name', 'value') + $expire;
  22. return;
  23. }
  24. $GLOBALS['mockedCookies'][] = compact(
  25. 'name',
  26. 'value',
  27. 'expire',
  28. 'path',
  29. 'domain',
  30. 'secure',
  31. 'httponly'
  32. );
  33. }