Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DbVersionInfoTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class DbVersionInfoTest extends \PHPUnit\Framework\TestCase
11 {
15  private $dbVersionInfo;
16 
20  private $moduleList;
21 
25  private $moduleResource;
26 
30  private $_outputConfig;
31 
32  protected function setUp()
33  {
34  $this->moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class);
35  $this->moduleList->expects($this->any())
36  ->method('getOne')
37  ->will($this->returnValueMap([
38  ['Module_One', ['name' => 'Module_One', 'setup_version' => '1']],
39  ['Module_Two', ['name' => 'Module_Two', 'setup_version' => '2']],
40  ['Module_No_Schema', []],
41  ]));
42  $this->moduleList->expects($this->any())
43  ->method('getNames')
44  ->will($this->returnValue(['Module_One', 'Module_Two']));
45 
46  $this->_outputConfig = $this->getMockForAbstractClass(\Magento\Framework\Module\Output\ConfigInterface::class);
47  $this->moduleResource = $this->getMockForAbstractClass(\Magento\Framework\Module\ResourceInterface::class);
48 
49  $this->dbVersionInfo = new DbVersionInfo(
50  $this->moduleList,
51  $this->moduleResource
52  );
53  }
54 
62  public function testIsDbSchemaUpToDate($moduleName, $dbVersion, $expectedResult)
63  {
64  $this->moduleResource->expects($this->once())
65  ->method('getDbVersion')
66  ->with($moduleName)
67  ->will($this->returnValue($dbVersion));
68  $this->moduleList->expects(self::once())
69  ->method('getOne')
70  ->with($moduleName)
71  ->willReturn(
72  ['setup_version' => $dbVersion]
73  );
74  $this->assertEquals(
75  $expectedResult,
76  $this->dbVersionInfo->isSchemaUpToDate($moduleName)
77  );
78  }
79 
87  public function testIsDbDataUpToDate($moduleName, $dbVersion, $expectedResult)
88  {
89  $this->moduleResource->expects($this->once())
90  ->method('getDataVersion')
91  ->with($moduleName)
92  ->will($this->returnValue($dbVersion));
93  $this->moduleList->expects(self::once())
94  ->method('getOne')
95  ->with($moduleName)
96  ->willReturn(
97  ['setup_version' => $dbVersion]
98  );
99  $this->assertEquals(
100  $expectedResult,
101  $this->dbVersionInfo->isDataUpToDate($moduleName)
102  );
103  }
104 
108  public function isDbUpToDateDataProvider()
109  {
110  return [
111  'version in config == version in db' => ['Module_One', '1', true],
112  'version in config < version in db' => [
113  'Module_One',
114  '2',
115  false
116  ],
117  'version in config > version in db' => [
118  'Module_Two',
119  '1',
120  false
121  ],
122  'no version in db' => [
123  'Module_One',
124  false,
125  false
126  ],
127  ];
128  }
129 
130  public function testGetDbVersionErrors()
131  {
132  $this->moduleResource->expects($this->any())
133  ->method('getDataVersion')
134  ->will($this->returnValue(2));
135  $this->moduleResource->expects($this->any())
136  ->method('getDbVersion')
137  ->will($this->returnValue(2));
138 
139  $expectedErrors = [
140  [
141  DbVersionInfo::KEY_MODULE => 'Module_One',
144  DbVersionInfo::KEY_TYPE => 'schema',
145  ],
146  [
147  DbVersionInfo::KEY_MODULE => 'Module_One',
150  DbVersionInfo::KEY_TYPE => 'data',
151  ]
152  ];
153  $this->assertEquals($expectedErrors, $this->dbVersionInfo->getDbVersionErrors());
154  }
155 
160  {
161  $this->assertTrue($this->dbVersionInfo->isSchemaUpToDate('Module_No_Schema'));
162  }
163 
168  {
169  $this->assertTrue($this->dbVersionInfo->isDataUpToDate('Module_No_Schema'));
170  }
171 }
testIsDbDataUpToDate($moduleName, $dbVersion, $expectedResult)
return false
Definition: gallery.phtml:36
testIsDbSchemaUpToDate($moduleName, $dbVersion, $expectedResult)