123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Setup;
- use Magento\Framework\Module\ModuleResource;
- use Magento\Framework\Setup\Patch\PatchHistory;
- use Magento\TestFramework\Deploy\CliCommand;
- use Magento\TestFramework\Deploy\TableData;
- use Magento\TestFramework\Deploy\TestModuleManager;
- use Magento\TestFramework\Helper\Bootstrap;
- use Magento\TestFramework\TestCase\SetupTestCase;
- use Magento\TestSetupDeclarationModule3\Setup\Patch\Data\IncrementalSomeIntegerPatch;
- use Magento\TestSetupDeclarationModule3\Setup\Patch\Data\ReferenceIncrementalSomeIntegerPatch;
- use Magento\TestSetupDeclarationModule3\Setup\Patch\Data\ZFirstPatch;
- /**
- * The purpose of this test is validating schema reader operations.
- */
- class DataPatchInstallationTest extends SetupTestCase
- {
- /**
- * @var TestModuleManager
- */
- private $moduleManager;
- /**
- * @var CliCommand
- */
- private $cliCommad;
- /**
- * @var ModuleResource
- */
- private $moduleResource;
- /**
- * @var PatchHistory
- */
- private $patchList;
- /**
- * @var TableData
- */
- private $tableData;
- public function setUp()
- {
- $objectManager = Bootstrap::getObjectManager();
- $this->moduleManager = $objectManager->get(TestModuleManager::class);
- $this->cliCommad = $objectManager->get(CliCommand::class);
- $this->moduleResource = $objectManager->get(ModuleResource::class);
- $this->patchList = $objectManager->get(PatchHistory::class);
- $this->tableData = $objectManager->get(TableData::class);
- }
- /**
- * @moduleName Magento_TestSetupDeclarationModule3
- */
- public function testDataPatchesInstallation()
- {
- $this->cliCommad->install(
- ['Magento_TestSetupDeclarationModule3']
- );
- self::assertEquals(
- '0.0.1',
- $this->moduleResource->getDataVersion('Magento_TestSetupDeclarationModule3')
- );
- $this->moduleManager->updateRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'first_patch_revision',
- 'module.xml',
- 'etc'
- );
- $this->movePatches();
- ModuleResource::flush();
- $this->cliCommad->upgrade();
- self::assertEquals(
- '0.0.3',
- $this->moduleResource->getDataVersion('Magento_TestSetupDeclarationModule3')
- );
- self::assertTrue($this->patchList->isApplied(IncrementalSomeIntegerPatch::class));
- self::assertTrue($this->patchList->isApplied(ReferenceIncrementalSomeIntegerPatch::class));
- self::assertTrue($this->patchList->isApplied(ZFirstPatch::class));
- $tableData = $this->tableData->describeTableData('test_table');
- self::assertEquals($this->getTestTableData(), $tableData);
- }
- /**
- * @moduleName Magento_TestSetupDeclarationModule3
- * @expectedException \Magento\Framework\Exception\LocalizedException
- */
- public function testCyclomaticDependency()
- {
- $this->moduleManager->updateRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'cyclomatic_and_bic_revision',
- 'module.xml',
- 'etc'
- );
- $this->movePatches();
- /**
- * Test whether installation give the same result as upgrade
- */
- $this->cliCommad->install(
- ['Magento_TestSetupDeclarationModule3']
- );
- $tableData = $this->tableData->describeTableData('test_table');
- self::assertEquals($this->getTestTableData(), $tableData);
- $this->moduleManager->updateRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'cyclomatic_and_bic_revision',
- 'BicPatch.php',
- 'Setup/Patch/Data'
- );
- $this->moduleManager->updateRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'cyclomatic_and_bic_revision',
- 'RefBicPatch.php',
- 'Setup/Patch/Data'
- );
- $this->cliCommad->upgrade();
- }
- /**
- * Move patches
- */
- private function movePatches()
- {
- //Install with patches
- $this->moduleManager->addRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'patches_revision',
- 'Setup/Patch/Data'
- );
- //Upgrade with UpgradeData
- $this->moduleManager->updateRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'first_patch_revision',
- 'UpgradeData.php',
- 'Setup'
- );
- //Upgrade with UpgradeData
- $this->moduleManager->updateRevision(
- 'Magento_TestSetupDeclarationModule3',
- 'first_patch_revision',
- 'module.xml',
- 'etc'
- );
- }
- /**
- * @moduleName Magento_TestSetupDeclarationModule3
- */
- public function testPatchesRevert()
- {
- $this->movePatches();
- $this->cliCommad->install(['Magento_TestSetupDeclarationModule3']);
- $this->cliCommad->uninstallModule('Magento_TestSetupDeclarationModule3');
- $testTableData = $this->tableData->describeTableData('test_table');
- $patchListTableData = $this->tableData->describeTableData('patch_list');
- self::assertEmpty($patchListTableData);
- self::assertEmpty($testTableData);
- $refTableData = $this->tableData->describeTableData('reference_table');
- self::assertEquals($this->getRefTableData(), $refTableData);
- }
- /**
- * @return array
- */
- private function getTestTableData()
- {
- return [
- [
- 'smallint' => '1',
- 'tinyint' => null,
- 'varchar' => 'Ololo123',
- 'varbinary' => '33288',
- ],
- [
- 'smallint' => '2',
- 'tinyint' => null,
- 'varchar' => 'Ololo123_ref',
- 'varbinary' => '33288',
- ],
- [
- 'smallint' => '3',
- 'tinyint' => null,
- 'varchar' => 'changed__very_secret_string',
- 'varbinary' => '0',
- ],
- ];
- }
- /**
- * Retrieve reference table data
- *
- * @return array
- */
- private function getRefTableData()
- {
- return [
- [
- 'tinyint_ref' => '2',
- 'some_integer' => '2',
- 'for_patch_testing' => null,
- ],
- [
- 'tinyint_ref' => '3',
- 'some_integer' => '3',
- 'for_patch_testing' => null,
- ],
- [
- 'tinyint_ref' => '4',
- 'some_integer' => '5',
- 'for_patch_testing' => null,
- ],
- [
- 'tinyint_ref' => '5',
- 'some_integer' => '6',
- 'for_patch_testing' => null,
- ],
- [
- 'tinyint_ref' => '6',
- 'some_integer' => '12',
- 'for_patch_testing' => null,
- ],
- ];
- }
- }
|