ConfigChangeDetectorTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Model\Plugin;
  7. use Magento\Deploy\Model\Plugin\ConfigChangeDetector;
  8. use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
  9. use Magento\Framework\App\FrontControllerInterface;
  10. use Magento\Framework\App\RequestInterface;
  11. class ConfigChangeDetectorTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var ConfigChangeDetector
  15. */
  16. private $configChangeDetectorPlugin;
  17. /**
  18. * @var ChangeDetector|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $changeDetectorMock;
  21. /**
  22. * @var FrontControllerInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $frontControllerMock;
  25. /**
  26. * @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $requestMock;
  29. /**
  30. * @return void
  31. */
  32. protected function setUp()
  33. {
  34. $this->changeDetectorMock = $this->getMockBuilder(ChangeDetector::class)
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $this->frontControllerMock = $this->getMockBuilder(FrontControllerInterface::class)
  38. ->getMockForAbstractClass();
  39. $this->requestMock = $this->getMockBuilder(RequestInterface::class)
  40. ->getMockForAbstractClass();
  41. $this->configChangeDetectorPlugin = new ConfigChangeDetector($this->changeDetectorMock);
  42. }
  43. /**
  44. * @return void
  45. */
  46. public function testBeforeDispatchWithoutException()
  47. {
  48. $this->changeDetectorMock->expects($this->once())
  49. ->method('hasChanges')
  50. ->willReturn(false);
  51. $this->configChangeDetectorPlugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
  52. }
  53. /**
  54. * @return void
  55. * @expectedException \Magento\Framework\Exception\LocalizedException
  56. * @codingStandardsIgnoreStart
  57. * @expectedExceptionMessage The configuration file has changed. Run the "app:config:import" or the "setup:upgrade" command to synchronize the configuration.
  58. * @codingStandardsIgnoreEnd
  59. */
  60. public function testBeforeDispatchWithException()
  61. {
  62. $this->changeDetectorMock->expects($this->once())
  63. ->method('hasChanges')
  64. ->willReturn(true);
  65. $this->configChangeDetectorPlugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
  66. }
  67. }