SetupInstallTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Developer\Console\Command;
  8. use Magento\Framework\Component\ComponentRegistrar;
  9. use Magento\TestFramework\Deploy\CliCommand;
  10. use Magento\TestFramework\Deploy\TestModuleManager;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. use Magento\TestFramework\TestCase\SetupTestCase;
  13. /**
  14. * Test for Install command.
  15. */
  16. class SetupInstallTest extends SetupTestCase
  17. {
  18. /**
  19. * @var TestModuleManager
  20. */
  21. private $moduleManager;
  22. /**
  23. * @var CliCommand
  24. */
  25. private $cliCommand;
  26. /**
  27. * @var ComponentRegistrar
  28. */
  29. private $componentRegistrar;
  30. /**
  31. * @inheritdoc
  32. */
  33. public function setUp()
  34. {
  35. $objectManager = Bootstrap::getObjectManager();
  36. $this->cliCommand = $objectManager->get(CliCommand::class);
  37. $this->moduleManager = $objectManager->get(TestModuleManager::class);
  38. $this->componentRegistrar = $objectManager->create(
  39. ComponentRegistrar::class
  40. );
  41. }
  42. /**
  43. * @moduleName Magento_TestSetupDeclarationModule8
  44. * @moduleName Magento_TestSetupDeclarationModule9
  45. * @throws \Exception
  46. */
  47. public function testInstallWithConverting()
  48. {
  49. $modules = [
  50. 'Magento_TestSetupDeclarationModule8',
  51. 'Magento_TestSetupDeclarationModule9',
  52. ];
  53. foreach ($modules as $moduleName) {
  54. $this->moduleManager->updateRevision(
  55. $moduleName,
  56. 'setup_install_with_converting',
  57. 'InstallSchema.php',
  58. 'Setup'
  59. );
  60. $this->moduleManager->updateRevision(
  61. $moduleName,
  62. 'setup_install_with_converting',
  63. 'UpgradeSchema.php',
  64. 'Setup'
  65. );
  66. $this->moduleManager->updateRevision(
  67. $moduleName,
  68. 'setup_install_with_converting',
  69. 'module.xml',
  70. 'etc'
  71. );
  72. }
  73. $this->cliCommand->install($modules, ['convert-old-scripts' => true]);
  74. foreach ($modules as $moduleName) {
  75. $modulePath = $this->componentRegistrar->getPath('module', $moduleName);
  76. $schemaFileName = $modulePath
  77. . DIRECTORY_SEPARATOR
  78. . \Magento\Framework\Module\Dir::MODULE_ETC_DIR
  79. . DIRECTORY_SEPARATOR
  80. . 'db_schema.xml';
  81. $generatedSchema = $this->getSchemaDocument($schemaFileName);
  82. $expectedSchemaFileName = dirname(__DIR__, 2)
  83. . DIRECTORY_SEPARATOR
  84. . implode(
  85. DIRECTORY_SEPARATOR,
  86. [
  87. '_files',
  88. 'SetupInstall',
  89. str_replace('Magento_', '', $moduleName),
  90. 'db_schema.xml'
  91. ]
  92. );
  93. $expectedSchema = $this->getSchemaDocument($expectedSchemaFileName);
  94. $this->assertEquals($expectedSchema->saveXML(), $generatedSchema->saveXML());
  95. }
  96. }
  97. /**
  98. * Convert file content in the DOM document.
  99. *
  100. * @param $schemaFileName
  101. * @return \DOMDocument
  102. */
  103. private function getSchemaDocument($schemaFileName): \DOMDocument
  104. {
  105. $schemaDocument = new \DOMDocument();
  106. $schemaDocument->preserveWhiteSpace = false;
  107. $schemaDocument->formatOutput = true;
  108. $schemaDocument->loadXML(file_get_contents($schemaFileName));
  109. return $schemaDocument;
  110. }
  111. }