Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateTestSchemaPaths.php
Go to the documentation of this file.
1 <?php
8 
9 use Symfony\Component\Console\Input\InputInterface;
10 use Symfony\Component\Filesystem\Filesystem;
11 use Symfony\Component\Finder\Finder;
12 
18 {
25  public function execute(InputInterface $input)
26  {
27  // @codingStandardsIgnoreStart
28  $relativeToUrn = [
29  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd"
30  => "urn:magento:mftf:DataGenerator/etc/dataOperation.xsd",
31  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd"
32  => "urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd",
33  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd"
34  => "urn:magento:mftf:Page/etc/PageObject.xsd",
35  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd"
36  => "urn:magento:mftf:Page/etc/SectionObject.xsd",
37  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd"
38  => "urn:magento:mftf:Test/etc/actionGroupSchema.xsd",
39  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd"
40  => "urn:magento:mftf:Test/etc/testSchema.xsd",
41  "dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Suite/etc/suiteSchema.xsd"
42  => "urn:magento:mftf:Suite/etc/suiteSchema.xsd"
43  ];
44  // @codingStandardsIgnoreEnd
45 
46  $relativePatterns = [];
47  $urns = [];
48  // Prepare array of patterns to URNs for preg_replace (replace / to escapes
49  foreach ($relativeToUrn as $relative => $urn) {
50  $relativeReplaced = str_replace('/', '\/', $relative);
51  $relativePatterns[] = '/[.\/]+' . $relativeReplaced . '/';
52  $urns[] = $urn;
53  }
54 
55  $testsPath = $input->getArgument('path');
56  $finder = new Finder();
57  $finder->files()->in($testsPath)->name("*.xml");
58 
59  $fileSystem = new Filesystem();
60  $testsUpdated = 0;
61  foreach ($finder->files() as $file) {
62  $count = 0;
63  $contents = $file->getContents();
64  $contents = preg_replace($relativePatterns, $urns, $contents, -1, $count);
65  $fileSystem->dumpFile($file->getRealPath(), $contents);
66  if ($count > 0) {
67  $testsUpdated++;
68  }
69  }
70 
71  return ("Schema Path updated to use MFTF URNs in {$testsUpdated} file(s).");
72  }
73 }
$contents
Definition: website.php:14
$count
Definition: recent.phtml:13