SchemaReaderTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup;
  7. use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
  8. use Magento\TestFramework\Deploy\TestModuleManager;
  9. use Magento\TestFramework\Helper\Bootstrap;
  10. use Magento\TestFramework\TestCase\SetupTestCase;
  11. /**
  12. * The purpose of this test is validating schema reader operations.
  13. */
  14. class SchemaReaderTest extends SetupTestCase
  15. {
  16. /**
  17. * @var \Magento\Framework\Setup\Declaration\Schema\FileSystem\XmlReader
  18. */
  19. private $reader;
  20. /**
  21. * @var TestModuleManager
  22. */
  23. private $moduleManager;
  24. public function setUp()
  25. {
  26. $objectManager = Bootstrap::getObjectManager();
  27. $this->reader = $objectManager->get(ReaderComposite::class);
  28. $this->moduleManager = $objectManager->get(TestModuleManager::class);
  29. }
  30. /**
  31. * @moduleName Magento_TestSetupDeclarationModule1
  32. * @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php
  33. */
  34. public function testSuccessfullRead()
  35. {
  36. $schema = $this->reader->read('all');
  37. unset($schema['table']['patch_list']);
  38. self::assertEquals($this->getData(), $schema);
  39. }
  40. /**
  41. * Helper method. Decrease number of params
  42. *
  43. * @param string $revisionName
  44. * @return void
  45. */
  46. private function updateRevisionTo($revisionName)
  47. {
  48. $this->moduleManager->updateRevision(
  49. 'Magento_TestSetupDeclarationModule1',
  50. $revisionName,
  51. TestModuleManager::DECLARATIVE_FILE_NAME,
  52. 'etc'
  53. );
  54. }
  55. /**
  56. * @expectedException \Magento\Framework\Exception\LocalizedException
  57. * @expectedExceptionMessageRegExp /The attribute 'scale' is not allowed./
  58. * @moduleName Magento_TestSetupDeclarationModule1
  59. */
  60. public function testFailOnInvalidColumnDeclaration()
  61. {
  62. $this->updateRevisionTo('fail_on_column_declaration');
  63. $this->reader->read('all');
  64. }
  65. /**
  66. * @moduleName Magento_TestSetupDeclarationModule1
  67. * @dataProviderFromFile Magento/TestSetupDeclarationModule1/fixture/foreign_key_interpreter_result.php
  68. */
  69. public function testForeignKeyInterpreter()
  70. {
  71. $this->updateRevisionTo('foreign_key_interpreter');
  72. $schema = $this->reader->read('all');
  73. unset($schema['table']['patch_list']);
  74. self::assertEquals($this->getData(), $schema);
  75. }
  76. }