IndexTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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;
  7. use Magento\Contact\Model\ConfigInterface;
  8. use Magento\Framework\App\RequestInterface;
  9. use Magento\Framework\App\ResponseInterface;
  10. class IndexTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Controller instance
  14. *
  15. * @var \Magento\Contact\Controller\Index
  16. */
  17. private $controller;
  18. /**
  19. * Module config instance
  20. *
  21. * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $configMock;
  24. protected function setUp()
  25. {
  26. $this->configMock = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass();
  27. $context = $this->getMockBuilder(
  28. \Magento\Framework\App\Action\Context::class
  29. )->setMethods(
  30. ['getRequest', 'getResponse']
  31. )->disableOriginalConstructor(
  32. )->getMock();
  33. $context->expects($this->any())
  34. ->method('getRequest')
  35. ->will(
  36. $this->returnValue(
  37. $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass()
  38. )
  39. );
  40. $context->expects($this->any())
  41. ->method('getResponse')
  42. ->will(
  43. $this->returnValue(
  44. $this->getMockBuilder(ResponseInterface::class)->getMockForAbstractClass()
  45. )
  46. );
  47. $this->controller = new \Magento\Contact\Test\Unit\Controller\Stub\IndexStub(
  48. $context,
  49. $this->configMock
  50. );
  51. }
  52. /**
  53. * Dispatch test
  54. *
  55. * @expectedException \Magento\Framework\Exception\NotFoundException
  56. */
  57. public function testDispatch()
  58. {
  59. $this->configMock->method('isEnabled')->willReturn(false);
  60. $this->controller->dispatch(
  61. $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass()
  62. );
  63. }
  64. }