Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataPatchInstallationTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Setup;
8 
19 
24 {
28  private $moduleManager;
29 
33  private $cliCommad;
34 
38  private $moduleResource;
39 
43  private $patchList;
44 
48  private $tableData;
49 
50  public function setUp()
51  {
53  $this->moduleManager = $objectManager->get(TestModuleManager::class);
54  $this->cliCommad = $objectManager->get(CliCommand::class);
55  $this->moduleResource = $objectManager->get(ModuleResource::class);
56  $this->patchList = $objectManager->get(PatchHistory::class);
57  $this->tableData = $objectManager->get(TableData::class);
58  }
59 
63  public function testDataPatchesInstallation()
64  {
65  $this->cliCommad->install(
66  ['Magento_TestSetupDeclarationModule3']
67  );
68 
69  self::assertEquals(
70  '0.0.1',
71  $this->moduleResource->getDataVersion('Magento_TestSetupDeclarationModule3')
72  );
73 
74  $this->moduleManager->updateRevision(
75  'Magento_TestSetupDeclarationModule3',
76  'first_patch_revision',
77  'module.xml',
78  'etc'
79  );
80  $this->movePatches();
82  $this->cliCommad->upgrade();
83  self::assertEquals(
84  '0.0.3',
85  $this->moduleResource->getDataVersion('Magento_TestSetupDeclarationModule3')
86  );
87  self::assertTrue($this->patchList->isApplied(IncrementalSomeIntegerPatch::class));
88  self::assertTrue($this->patchList->isApplied(ReferenceIncrementalSomeIntegerPatch::class));
89  self::assertTrue($this->patchList->isApplied(ZFirstPatch::class));
90  $tableData = $this->tableData->describeTableData('test_table');
91  self::assertEquals($this->getTestTableData(), $tableData);
92  }
93 
98  public function testCyclomaticDependency()
99  {
100  $this->moduleManager->updateRevision(
101  'Magento_TestSetupDeclarationModule3',
102  'cyclomatic_and_bic_revision',
103  'module.xml',
104  'etc'
105  );
106 
107  $this->movePatches();
111  $this->cliCommad->install(
112  ['Magento_TestSetupDeclarationModule3']
113  );
114  $tableData = $this->tableData->describeTableData('test_table');
115  self::assertEquals($this->getTestTableData(), $tableData);
116  $this->moduleManager->updateRevision(
117  'Magento_TestSetupDeclarationModule3',
118  'cyclomatic_and_bic_revision',
119  'BicPatch.php',
120  'Setup/Patch/Data'
121  );
122  $this->moduleManager->updateRevision(
123  'Magento_TestSetupDeclarationModule3',
124  'cyclomatic_and_bic_revision',
125  'RefBicPatch.php',
126  'Setup/Patch/Data'
127  );
128 
129  $this->cliCommad->upgrade();
130  }
131 
135  private function movePatches()
136  {
137  //Install with patches
138  $this->moduleManager->addRevision(
139  'Magento_TestSetupDeclarationModule3',
140  'patches_revision',
141  'Setup/Patch/Data'
142  );
143  //Upgrade with UpgradeData
144  $this->moduleManager->updateRevision(
145  'Magento_TestSetupDeclarationModule3',
146  'first_patch_revision',
147  'UpgradeData.php',
148  'Setup'
149  );
150 
151  //Upgrade with UpgradeData
152  $this->moduleManager->updateRevision(
153  'Magento_TestSetupDeclarationModule3',
154  'first_patch_revision',
155  'module.xml',
156  'etc'
157  );
158  }
159 
163  public function testPatchesRevert()
164  {
165  $this->movePatches();
166  $this->cliCommad->install(['Magento_TestSetupDeclarationModule3']);
167  $this->cliCommad->uninstallModule('Magento_TestSetupDeclarationModule3');
168  $testTableData = $this->tableData->describeTableData('test_table');
169  $patchListTableData = $this->tableData->describeTableData('patch_list');
170  self::assertEmpty($patchListTableData);
171  self::assertEmpty($testTableData);
172  $refTableData = $this->tableData->describeTableData('reference_table');
173  self::assertEquals($this->getRefTableData(), $refTableData);
174  }
175 
179  private function getTestTableData()
180  {
181  return [
182  [
183  'smallint' => '1',
184  'tinyint' => null,
185  'varchar' => 'Ololo123',
186  'varbinary' => '33288',
187  ],
188  [
189  'smallint' => '2',
190  'tinyint' => null,
191  'varchar' => 'Ololo123_ref',
192  'varbinary' => '33288',
193  ],
194  [
195  'smallint' => '3',
196  'tinyint' => null,
197  'varchar' => 'changed__very_secret_string',
198  'varbinary' => '0',
199  ],
200  ];
201  }
202 
208  private function getRefTableData()
209  {
210  return [
211  [
212  'tinyint_ref' => '2',
213  'some_integer' => '2',
214  'for_patch_testing' => null,
215  ],
216  [
217  'tinyint_ref' => '3',
218  'some_integer' => '3',
219  'for_patch_testing' => null,
220  ],
221  [
222  'tinyint_ref' => '4',
223  'some_integer' => '5',
224  'for_patch_testing' => null,
225  ],
226  [
227  'tinyint_ref' => '5',
228  'some_integer' => '6',
229  'for_patch_testing' => null,
230  ],
231  [
232  'tinyint_ref' => '6',
233  'some_integer' => '12',
234  'for_patch_testing' => null,
235  ],
236  ];
237  }
238 }
$objectManager
Definition: bootstrap.php:17