IndexTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Contact\Test\Unit\Controller\Index;
  7. use Magento\Contact\Model\ConfigInterface;
  8. use Magento\Framework\Controller\ResultFactory;
  9. use Magento\Framework\Controller\ResultInterface;
  10. class IndexTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Contact\Controller\Index\Index
  14. */
  15. private $controller;
  16. /**
  17. * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $configMock;
  20. /**
  21. * @var ResultFactory|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $resultFactory;
  24. /**
  25. * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $url;
  28. protected function setUp()
  29. {
  30. $this->configMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass();
  31. $context = $this->getMockBuilder(
  32. \Magento\Framework\App\Action\Context::class
  33. )->setMethods(
  34. ['getRequest', 'getResponse', 'getResultFactory', 'getUrl']
  35. )->disableOriginalConstructor(
  36. )->getMock();
  37. $this->url = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)->getMockForAbstractClass();
  38. $context->expects($this->any())
  39. ->method('getUrl')
  40. ->will($this->returnValue($this->url));
  41. $context->expects($this->any())
  42. ->method('getRequest')
  43. ->will($this->returnValue(
  44. $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)->getMockForAbstractClass()
  45. ));
  46. $context->expects($this->any())
  47. ->method('getResponse')
  48. ->will($this->returnValue(
  49. $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)->getMockForAbstractClass()
  50. ));
  51. $this->resultFactory = $this->getMockBuilder(
  52. ResultFactory::class
  53. )->disableOriginalConstructor(
  54. )->getMock();
  55. $context->expects($this->once())
  56. ->method('getResultFactory')
  57. ->will($this->returnValue($this->resultFactory));
  58. $this->controller = new \Magento\Contact\Controller\Index\Index(
  59. $context,
  60. $this->configMock
  61. );
  62. }
  63. public function testExecute()
  64. {
  65. $resultStub = $this->getMockForAbstractClass(ResultInterface::class);
  66. $this->resultFactory->expects($this->once())
  67. ->method('create')
  68. ->with(ResultFactory::TYPE_PAGE)
  69. ->willReturn($resultStub);
  70. $this->assertSame($resultStub, $this->controller->execute());
  71. }
  72. }