123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- declare(strict_types=1);
- namespace Magento\Developer\Console\Command;
- use Magento\Framework\Component\ComponentRegistrar;
- use Magento\TestFramework\Deploy\CliCommand;
- use Magento\TestFramework\Deploy\TestModuleManager;
- use Magento\TestFramework\Helper\Bootstrap;
- use Magento\TestFramework\TestCase\SetupTestCase;
- /**
- * Test for Upgrade command.
- */
- class SetupUpgradeTest extends SetupTestCase
- {
- /**
- * @var TestModuleManager
- */
- private $moduleManager;
- /**
- * @var CliCommand
- */
- private $cliCommand;
- /**
- * @var ComponentRegistrar
- */
- private $componentRegistrar;
- /**
- * @inheritdoc
- */
- public function setUp()
- {
- $objectManager = Bootstrap::getObjectManager();
- $this->cliCommand = $objectManager->get(CliCommand::class);
- $this->moduleManager = $objectManager->get(TestModuleManager::class);
- $this->componentRegistrar = $objectManager->create(
- ComponentRegistrar::class
- );
- }
- /**
- * @moduleName Magento_TestSetupDeclarationModule8
- * @moduleName Magento_TestSetupDeclarationModule9
- * @throws \Exception
- */
- public function testUpgradeWithConverting()
- {
- $modules = [
- 'Magento_TestSetupDeclarationModule8',
- 'Magento_TestSetupDeclarationModule9',
- ];
- foreach ($modules as $moduleName) {
- $this->moduleManager->updateRevision(
- $moduleName,
- 'setup_install_with_converting',
- 'InstallSchema.php',
- 'Setup'
- );
- }
- $this->cliCommand->install($modules, ['convert-old-scripts' => true]);
- foreach ($modules as $moduleName) {
- $this->assertInstallScriptChanges($moduleName);
- }
- foreach ($modules as $moduleName) {
- $this->moduleManager->updateRevision(
- $moduleName,
- 'setup_install_with_converting',
- 'UpgradeSchema.php',
- 'Setup'
- );
- $this->moduleManager->updateRevision(
- $moduleName,
- 'setup_install_with_converting',
- 'module.xml',
- 'etc'
- );
- }
- $this->cliCommand->upgrade(['convert-old-scripts' => true]);
- foreach ($modules as $moduleName) {
- $this->assertUpgradeScriptChanges($moduleName);
- }
- }
- /**
- * Convert file content in the DOM document.
- *
- * @param string $schemaFileName
- * @return \DOMDocument
- */
- private function getSchemaDocument(string $schemaFileName): \DOMDocument
- {
- $schemaDocument = new \DOMDocument();
- $schemaDocument->preserveWhiteSpace = false;
- $schemaDocument->formatOutput = true;
- $schemaDocument->loadXML(file_get_contents($schemaFileName));
- return $schemaDocument;
- }
- /**
- * @param string $moduleName
- */
- private function assertInstallScriptChanges(string $moduleName): void
- {
- $generatedSchema = $this->getGeneratedSchema($moduleName);
- $expectedSchema = $this->getSchemaDocument($this->getSchemaFixturePath($moduleName, 'install'));
- $this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
- }
- /**
- * @param string $moduleName
- */
- private function assertUpgradeScriptChanges(string $moduleName): void
- {
- $generatedSchema = $this->getGeneratedSchema($moduleName);
- $expectedSchema = $this->getSchemaDocument($this->getSchemaFixturePath($moduleName, 'upgrade'));
- $this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
- }
- /**
- * @param string $moduleName
- * @return \DOMDocument
- */
- private function getGeneratedSchema(string $moduleName): \DOMDocument
- {
- $modulePath = $this->componentRegistrar->getPath('module', $moduleName);
- $schemaFileName = $modulePath
- . DIRECTORY_SEPARATOR
- . \Magento\Framework\Module\Dir::MODULE_ETC_DIR
- . DIRECTORY_SEPARATOR
- . 'db_schema.xml';
- return $this->getSchemaDocument($schemaFileName);
- }
- /**
- * @param string $moduleName
- * @param string $suffix
- * @return string
- */
- private function getSchemaFixturePath(string $moduleName, string $suffix): string
- {
- $schemaFixturePath = dirname(__DIR__, 2)
- . DIRECTORY_SEPARATOR
- . implode(
- DIRECTORY_SEPARATOR,
- [
- '_files',
- 'SetupUpgrade',
- str_replace('Magento_', '', $moduleName),
- 'db_schema_' . $suffix . '.xml'
- ]
- );
- return $schemaFixturePath;
- }
- }
|