AbstractActionTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Test\Unit\Action;
  7. class AbstractActionTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Framework\App\Action\AbstractAction|\PHPUnit_Framework_MockObject_MockObject */
  10. protected $action;
  11. /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
  12. protected $request;
  13. /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */
  14. protected $response;
  15. /** @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject */
  16. protected $redirectFactory;
  17. /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject */
  18. protected $redirect;
  19. /** @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject */
  20. protected $context;
  21. protected function setUp()
  22. {
  23. $this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
  24. ->disableOriginalConstructor()->getMock();
  25. $this->response = $this->createMock(\Magento\Framework\App\ResponseInterface::class);
  26. $this->redirect = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
  27. ->setMethods(['setRefererOrBaseUrl'])
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $this->redirectFactory = $this->getMockBuilder(\Magento\Framework\Controller\Result\RedirectFactory::class)
  31. ->setMethods(['create'])
  32. ->disableOriginalConstructor()
  33. ->getMock();
  34. $this->redirectFactory->expects($this->any())
  35. ->method('create')
  36. ->willReturn($this->redirect);
  37. $this->context = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
  38. ->disableOriginalConstructor()
  39. ->getMock();
  40. $this->context->expects($this->any())
  41. ->method('getResultRedirectFactory')
  42. ->willReturn($this->redirectFactory);
  43. $this->context->expects($this->once())
  44. ->method('getRequest')
  45. ->willReturn($this->request);
  46. $this->context->expects($this->once())
  47. ->method('getResponse')
  48. ->willReturn($this->response);
  49. $this->action = $this->getMockForAbstractClass(
  50. \Magento\Framework\App\Action\AbstractAction::class,
  51. [$this->context]
  52. );
  53. }
  54. public function testGetRequest()
  55. {
  56. $this->assertEquals($this->request, $this->action->getRequest());
  57. }
  58. public function testGetResponse()
  59. {
  60. $this->assertEquals($this->response, $this->action->getResponse());
  61. }
  62. }