Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InstallUpgradeTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Test\Legacy;
8 
12 
16 class InstallUpgradeTest extends \PHPUnit\Framework\TestCase
17 {
19  {
20  $scriptPattern = [];
22  foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $moduleDir) {
23  $scriptPattern[] = $moduleDir . '/sql';
24  $scriptPattern[] = $moduleDir . '/data';
25  $scriptPattern[] = $moduleDir . '/Setup';
26  }
27  $invoker = new AggregateInvoker($this);
28  $invoker(
32  function ($file) {
33  $this->assertStringStartsNotWith(
34  'install-',
35  basename($file),
36  'Install scripts are obsolete. '
37  . 'Please use declarative schema approach in module\'s etc/db_schema.xml file'
38  );
39  $this->assertStringStartsNotWith(
40  'InstallSchema',
41  basename($file),
42  'InstallSchema objects are obsolete. '
43  . 'Please use declarative schema approach in module\'s etc/db_schema.xml file'
44  );
45  $this->assertStringStartsNotWith(
46  'InstallData',
47  basename($file),
48  'InstallData objects are obsolete. '
49  . 'Please use data patches approach in module\'s Setup/Patch/Data dir'
50  );
51  $this->assertStringStartsNotWith(
52  'data-install-',
53  basename($file),
54  'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder'
55  );
56  $this->assertStringStartsNotWith(
57  'upgrade-',
58  basename($file),
59  'Upgrade scripts are obsolete. '
60  . 'Please use declarative schema approach in module\'s etc/db_schema.xml file'
61  );
62  $this->assertStringStartsNotWith(
63  'UpgradeSchema',
64  basename($file),
65  'UpgradeSchema scripts are obsolete. '
66  . 'Please use declarative schema approach in module\'s etc/db_schema.xml file'
67  );
68  $this->assertStringStartsNotWith(
69  'UpgradeData',
70  basename($file),
71  'UpgradeSchema scripts are obsolete. '
72  . 'Please use data patches approach in module\'s Setup/Patch/Data dir'
73  );
74  $this->assertStringStartsNotWith(
75  'data-upgrade-',
76  basename($file),
77  'Upgrade scripts are obsolete. '
78  . 'Please use data patches approach in module\'s Setup/Patch/Data dir'
79  );
80  $this->assertStringStartsNotWith(
81  'recurring',
82  basename($file),
83  'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder'
84  );
85  if (preg_match('/.*\/(sql\/|data\/)/', dirname($file))) {
86  $this->fail(
87  "Invalid directory:\n"
88  . "- Create an data patch within module's Setup/Patch/Data folder for data upgrades.\n"
89  . "- Use declarative schema approach in module's etc/db_schema.xml file for schema changes."
90  );
91  }
92  },
93  $this->convertArray(
94  Files::init()->getFiles($scriptPattern, '*.php')
95  )
96  );
97  }
98 
105  private function convertArray($stringArray)
106  {
107  $array = [];
108  foreach ($stringArray as $item) {
109  $array[] = [$item];
110  }
111  return $array;
112  }
113 }
$componentRegistrar
Definition: bootstrap.php:23