-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathRenameMetadataFiles.php
72 lines (65 loc) · 2.18 KB
/
RenameMetadataFiles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Upgrade;
use Magento\FunctionalTestingFramework\Util\Script\ScriptUtil;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
/**
* Class RenameMetadataFiles
* @package Magento\FunctionalTestingFramework\Upgrade
*/
class RenameMetadataFiles implements UpgradeInterface
{
/**
* Upgrades all test xml files
*
* @param InputInterface $input
* @param OutputInterface $output
* @return string
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$testPaths[] = $input->getArgument('path');
if (empty($testPaths[0])) {
$testPaths = ScriptUtil::getAllModulePaths();
}
foreach ($testPaths as $testsPath) {
$finder = new Finder();
$finder->files()->in($testsPath)->name("*-meta.xml");
foreach ($finder->files() as $file) {
$oldFileName = $file->getFileName();
$newFileName = $this->convertFileName($oldFileName);
$oldPath = $file->getPathname();
$newPath = $file->getPath() . "/" . $newFileName;
print("Renaming " . $oldPath . " => " . $newPath . "\n");
rename($oldPath, $newPath);
}
}
return "Finished renaming -meta.xml files.";
}
/**
* Convert filenames like:
* user_role-meta.xml => UserRoleMeta.xml
* store-meta.xml => StoreMeta.xml
*
* @param string $oldFileName
* @return string
*/
private function convertFileName(string $oldFileName)
{
$stripEnding = preg_replace("/-meta.xml/", "", $oldFileName);
$hyphenToUnderscore = str_replace("-", "_", $stripEnding);
$parts = explode("_", $hyphenToUnderscore);
$ucParts = [];
foreach ($parts as $part) {
$ucParts[] = ucfirst($part);
}
$recombine = join("", $ucParts);
$addEnding = $recombine . "Meta.xml";
return $addEnding;
}
}