ChangeDetectorTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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\DeploymentConfig;
  7. use Magento\Deploy\Model\DeploymentConfig\Hash\Generator as HashGenerator;
  8. use Magento\Deploy\Model\DeploymentConfig\Hash;
  9. use Magento\Deploy\Model\DeploymentConfig\DataCollector;
  10. use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
  11. class ChangeDetectorTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var Hash|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. private $configHashMock;
  17. /**
  18. * @var HashGenerator|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $hashGeneratorMock;
  21. /**
  22. * @var DataCollector|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $dataConfigCollectorMock;
  25. /**
  26. * @var ChangeDetector
  27. */
  28. private $changeDetector;
  29. /**
  30. * @return void
  31. */
  32. protected function setUp()
  33. {
  34. $this->configHashMock = $this->getMockBuilder(Hash::class)
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $this->hashGeneratorMock = $this->getMockBuilder(HashGenerator::class)
  38. ->disableOriginalConstructor()
  39. ->getMock();
  40. $this->dataConfigCollectorMock = $this->getMockBuilder(DataCollector::class)
  41. ->disableOriginalConstructor()
  42. ->getMock();
  43. $this->changeDetector = new ChangeDetector(
  44. $this->configHashMock,
  45. $this->hashGeneratorMock,
  46. $this->dataConfigCollectorMock
  47. );
  48. }
  49. /**
  50. * @param string $sectionName
  51. * @param array $fullConfigData
  52. * @param string|null $configData
  53. * @param string $generatedHash
  54. * @param string $savedHash
  55. * @param bool $expectedResult
  56. * @return void
  57. * @dataProvider hasChangesDataProvider
  58. */
  59. public function testHasChanges(
  60. $sectionName,
  61. $fullConfigData,
  62. $configData,
  63. $generatedHash,
  64. $savedHash,
  65. $expectedResult
  66. ) {
  67. $this->dataConfigCollectorMock->expects($this->once())
  68. ->method('getConfig')
  69. ->with($sectionName)
  70. ->willReturn($fullConfigData);
  71. $this->hashGeneratorMock->expects($this->any())
  72. ->method('generate')
  73. ->with($configData)
  74. ->willReturn($generatedHash);
  75. $this->configHashMock->expects($this->any())
  76. ->method('get')
  77. ->willReturn($savedHash);
  78. $this->assertSame($expectedResult, $this->changeDetector->hasChanges($sectionName));
  79. }
  80. /**
  81. * @return array
  82. */
  83. public function hasChangesDataProvider()
  84. {
  85. return [
  86. [
  87. 'sectionName' => null,
  88. 'fullConfigData' => ['section' => 'some data'],
  89. 'configData' => 'some data',
  90. 'generatedHash' => '123',
  91. 'savedHash' => ['section' => '123'],
  92. 'expectedResult' => false
  93. ],
  94. [
  95. 'sectionName' => 'section',
  96. 'fullConfigData' => ['section' => 'some data'],
  97. 'configData' => 'some data',
  98. 'generatedHash' => '321',
  99. 'savedHash' => ['section' => '123'],
  100. 'expectedResult' => true
  101. ],
  102. [
  103. 'sectionName' => null,
  104. 'fullConfigData' => ['section' => 'some data'],
  105. 'configData' => 'some data',
  106. 'generatedHash' => '321',
  107. 'savedHash' => [],
  108. 'expectedResult' => true
  109. ],
  110. [
  111. 'sectionName' => 'section',
  112. 'fullConfigData' => [],
  113. 'configData' => null,
  114. 'generatedHash' => '321',
  115. 'savedHash' => ['section' => '123'],
  116. 'expectedResult' => false
  117. ],
  118. [
  119. 'sectionName' => null,
  120. 'fullConfigData' => [],
  121. 'configData' => null,
  122. 'generatedHash' => '321',
  123. 'savedHash' => [],
  124. 'expectedResult' => false
  125. ],
  126. ];
  127. }
  128. }