Request.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework;
  7. use \Zend\Stdlib\ParametersInterface;
  8. /**
  9. * HTTP request implementation that is used instead core one for testing
  10. */
  11. class Request extends \Magento\Framework\App\Request\Http
  12. {
  13. /**
  14. * Server super-global mock
  15. *
  16. * @var ParametersInterface
  17. */
  18. protected $_server;
  19. /**
  20. * Retrieve HTTP HOST.
  21. * This method is a stub - all parameters are ignored, just static value returned.
  22. *
  23. * @param bool $trimPort
  24. * @return string
  25. *
  26. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  27. */
  28. public function getHttpHost($trimPort = true)
  29. {
  30. return $trimPort ? 'localhost' : 'localhost:81';
  31. }
  32. /**
  33. * Set "server" super-global mock
  34. *
  35. * @param ParametersInterface $server
  36. * @return \Magento\TestFramework\Request
  37. */
  38. public function setServer(ParametersInterface $server)
  39. {
  40. $this->_server = $server;
  41. return $this;
  42. }
  43. /**
  44. * Overridden getter to avoid using of $_SERVER
  45. *
  46. * @param string|null $name
  47. * @param mixed|null $default
  48. * @return ParametersInterface|array|mixed|null
  49. */
  50. public function getServer($name = null, $default = null)
  51. {
  52. if (null === $name) {
  53. return $this->_server;
  54. }
  55. return $this->_server->get($name, $default);
  56. }
  57. }