Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ChangeDetectorTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class ChangeDetectorTest extends \PHPUnit\Framework\TestCase
14 {
18  private $configHashMock;
19 
23  private $hashGeneratorMock;
24 
28  private $dataConfigCollectorMock;
29 
33  private $changeDetector;
34 
38  protected function setUp()
39  {
40  $this->configHashMock = $this->getMockBuilder(Hash::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43  $this->hashGeneratorMock = $this->getMockBuilder(HashGenerator::class)
44  ->disableOriginalConstructor()
45  ->getMock();
46  $this->dataConfigCollectorMock = $this->getMockBuilder(DataCollector::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49 
50  $this->changeDetector = new ChangeDetector(
51  $this->configHashMock,
52  $this->hashGeneratorMock,
53  $this->dataConfigCollectorMock
54  );
55  }
56 
67  public function testHasChanges(
68  $sectionName,
69  $fullConfigData,
71  $generatedHash,
72  $savedHash,
73  $expectedResult
74  ) {
75  $this->dataConfigCollectorMock->expects($this->once())
76  ->method('getConfig')
77  ->with($sectionName)
78  ->willReturn($fullConfigData);
79  $this->hashGeneratorMock->expects($this->any())
80  ->method('generate')
81  ->with($configData)
82  ->willReturn($generatedHash);
83  $this->configHashMock->expects($this->any())
84  ->method('get')
85  ->willReturn($savedHash);
86 
87  $this->assertSame($expectedResult, $this->changeDetector->hasChanges($sectionName));
88  }
89 
93  public function hasChangesDataProvider()
94  {
95  return [
96  [
97  'sectionName' => null,
98  'fullConfigData' => ['section' => 'some data'],
99  'configData' => 'some data',
100  'generatedHash' => '123',
101  'savedHash' => ['section' => '123'],
102  'expectedResult' => false
103  ],
104  [
105  'sectionName' => 'section',
106  'fullConfigData' => ['section' => 'some data'],
107  'configData' => 'some data',
108  'generatedHash' => '321',
109  'savedHash' => ['section' => '123'],
110  'expectedResult' => true
111  ],
112  [
113  'sectionName' => null,
114  'fullConfigData' => ['section' => 'some data'],
115  'configData' => 'some data',
116  'generatedHash' => '321',
117  'savedHash' => [],
118  'expectedResult' => true
119  ],
120  [
121  'sectionName' => 'section',
122  'fullConfigData' => [],
123  'configData' => null,
124  'generatedHash' => '321',
125  'savedHash' => ['section' => '123'],
126  'expectedResult' => false
127  ],
128  [
129  'sectionName' => null,
130  'fullConfigData' => [],
131  'configData' => null,
132  'generatedHash' => '321',
133  'savedHash' => [],
134  'expectedResult' => false
135  ],
136  ];
137  }
138 }
return false
Definition: gallery.phtml:36
testHasChanges( $sectionName, $fullConfigData, $configData, $generatedHash, $savedHash, $expectedResult)