ValidationRulesTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\SchemaConfig;
  8. use Magento\TestFramework\Deploy\CliCommand;
  9. use Magento\TestFramework\Deploy\TestModuleManager;
  10. use Magento\TestFramework\Helper\Bootstrap;
  11. use Magento\TestFramework\TestCase\SetupTestCase;
  12. /**
  13. * The purpose of this test is verifying initial InstallSchema, InstallData scripts.
  14. */
  15. class ValidationRulesTest extends SetupTestCase
  16. {
  17. /**
  18. * @var TestModuleManager
  19. */
  20. private $moduleManager;
  21. /**
  22. * @var SchemaConfig
  23. */
  24. private $schemaConfig;
  25. /**
  26. * @var CliCommand
  27. */
  28. private $cliCommad;
  29. public function setUp()
  30. {
  31. $objectManager = Bootstrap::getObjectManager();
  32. $this->schemaConfig = $objectManager->create(SchemaConfig::class);
  33. $this->moduleManager = $objectManager->get(TestModuleManager::class);
  34. $this->cliCommad = $objectManager->get(CliCommand::class);
  35. }
  36. /**
  37. * @expectedException \Magento\Framework\Setup\Exception
  38. * @expectedExceptionMessageRegExp
  39. * /Primary key can`t be applied on table "test_table". All columns should be not nullable/
  40. * @moduleName Magento_TestSetupDeclarationModule8
  41. */
  42. public function testFailOnInvalidPrimaryKey()
  43. {
  44. $this->cliCommad->install(
  45. ['Magento_TestSetupDeclarationModule8']
  46. );
  47. $this->moduleManager->updateRevision(
  48. 'Magento_TestSetupDeclarationModule8',
  49. 'invalid_primary_key',
  50. 'db_schema.xml',
  51. 'etc'
  52. );
  53. $this->schemaConfig->getDeclarationConfig();
  54. }
  55. /**
  56. * @expectedException \Magento\Framework\Setup\Exception
  57. * @expectedExceptionMessageRegExp
  58. * /Column definition "page_id_on" and reference column definition "page_id"
  59. * are different in tables "dependent" and "test_table"/
  60. * @moduleName Magento_TestSetupDeclarationModule8
  61. */
  62. public function testFailOnIncosistentReferenceDefinition()
  63. {
  64. $this->cliCommad->install(
  65. ['Magento_TestSetupDeclarationModule8']
  66. );
  67. $this->moduleManager->updateRevision(
  68. 'Magento_TestSetupDeclarationModule8',
  69. 'incosistence_reference_definition',
  70. 'db_schema.xml',
  71. 'etc'
  72. );
  73. $this->schemaConfig->getDeclarationConfig();
  74. }
  75. /**
  76. * @expectedException \Magento\Framework\Setup\Exception
  77. * @expectedExceptionMessageRegExp /Auto Increment column do not have index. Column - "page_id"/
  78. * @moduleName Magento_TestSetupDeclarationModule8
  79. */
  80. public function testFailOnInvalidAutoIncrementField()
  81. {
  82. $this->cliCommad->install(
  83. ['Magento_TestSetupDeclarationModule8']
  84. );
  85. $this->moduleManager->updateRevision(
  86. 'Magento_TestSetupDeclarationModule8',
  87. 'invalid_auto_increment',
  88. 'db_schema.xml',
  89. 'etc'
  90. );
  91. $this->schemaConfig->getDeclarationConfig();
  92. }
  93. }