Skip to content

Commit a9b6d5d

Browse files
committed
minor #1045 Handle phpunit.xml.dist as an alias of phpunit.dist.xml (nicolas-grekas)
This PR was merged into the 2.x branch. Discussion ---------- Handle phpunit.xml.dist as an alias of phpunit.dist.xml Should smoothen the transition from phpunit.xml.dist to phpunit.dist.xml Tested on a small app where the file is renamed between installation and removal of phpunit/phpunit, flex tracks the move successfully. Commits ------- 3a62dd9 Handle phpunit.xml.dist as an alias of phpunit.dist.xml
2 parents 62d5c38 + 3a62dd9 commit a9b6d5d

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/Command/InstallRecipesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
130130
rename($dotenvPath, $dotenvPath.'.local');
131131
$pipes = [];
132132
proc_close(proc_open(\sprintf('git mv %s %s > %s 2>&1 || %s %1$s %2$s', ProcessExecutor::escape($dotenvFile.'.dist'), ProcessExecutor::escape($dotenvFile), $win ? 'NUL' : '/dev/null', $win ? 'rename' : 'mv'), $pipes, $pipes, $this->rootDir));
133-
if (file_exists($this->rootDir.'/phpunit.xml.dist')) {
133+
if (file_exists($this->rootDir.'/phpunit.xml.dist') || file_exists($this->rootDir.'/phpunit.dist.xml')) {
134134
touch($dotenvPath.'.test');
135135
}
136136
}

src/Configurator/CopyFromPackageConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function getFilesToCopy(array $manifest, string $from): array
7272
foreach ($manifest as $source => $target) {
7373
$target = $this->options->expandTargetDir($target);
7474
if ('/' === substr($source, -1)) {
75-
$files = array_merge($files, $this->getFilesForDir($this->path->concatenate([$from, $source]), $this->path->concatenate([$target])));
75+
$files = array_merge($files, $this->getFilesForDir($this->path->concatenate([$from, $source]), $target));
7676

7777
continue;
7878
}
@@ -118,7 +118,7 @@ private function getFilesForDir(string $source, string $target): array
118118
*/
119119
public function copyFile(string $source, string $target, array $options)
120120
{
121-
$target = $this->options->get('root-dir').'/'.$target;
121+
$target = $this->options->get('root-dir').'/'.$this->options->expandTargetDir($target);
122122
if (is_dir($source)) {
123123
// directory will be created when a file is copied to it
124124
return;

src/Configurator/EnvConfigurator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function configureEnvDist(Recipe $recipe, $vars, bool $update)
108108

109109
private function configurePhpUnit(Recipe $recipe, $vars, bool $update)
110110
{
111-
foreach (['phpunit.xml.dist', 'phpunit.xml'] as $file) {
111+
foreach (['phpunit.xml.dist', 'phpunit.dist.xml', 'phpunit.xml'] as $file) {
112112
$phpunit = $this->options->get('root-dir').'/'.$file;
113113
if (!is_file($phpunit)) {
114114
continue;
@@ -173,7 +173,7 @@ private function unconfigureEnvFiles(Recipe $recipe, $vars)
173173

174174
private function unconfigurePhpUnit(Recipe $recipe, $vars)
175175
{
176-
foreach (['phpunit.xml.dist', 'phpunit.xml'] as $file) {
176+
foreach (['phpunit.dist.xml', 'phpunit.xml.dist', 'phpunit.xml'] as $file) {
177177
$phpunit = $this->options->get('root-dir').'/'.$file;
178178
if (!is_file($phpunit)) {
179179
continue;
@@ -223,7 +223,7 @@ private function generateRandomBytes($length = 16)
223223
private function getContentsAfterApplyingRecipe(string $rootDir, Recipe $recipe, array $vars): array
224224
{
225225
$dotenvPath = $this->options->get('runtime')['dotenv_path'] ?? '.env';
226-
$files = '' === $this->suffix ? [$dotenvPath, $dotenvPath.'.dist', 'phpunit.xml.dist', 'phpunit.xml'] : [$dotenvPath.'.'.$this->suffix];
226+
$files = '' === $this->suffix ? [$dotenvPath, $dotenvPath.'.dist', 'phpunit.dist.xml', 'phpunit.xml.dist', 'phpunit.xml'] : [$dotenvPath.'.'.$this->suffix];
227227

228228
if (0 === \count($vars)) {
229229
return array_fill_keys($files, null);

src/Options.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,30 @@ public function get(string $name)
3636

3737
public function expandTargetDir(string $target): string
3838
{
39-
return preg_replace_callback('{%(.+?)%}', function ($matches) {
39+
$result = preg_replace_callback('{%(.+?)%}', function ($matches) {
4040
$option = str_replace('_', '-', strtolower($matches[1]));
4141
if (!isset($this->options[$option])) {
4242
return $matches[0];
4343
}
4444

4545
return rtrim($this->options[$option], '/');
4646
}, $target);
47+
48+
$phpunitDistFiles = [
49+
'phpunit.xml.dist' => true,
50+
'phpunit.dist.xml' => true,
51+
];
52+
53+
$rootDir = $this->get('root-dir');
54+
55+
if (null === $rootDir || !isset($phpunitDistFiles[$result]) || !is_dir($rootDir) || file_exists($rootDir.'/'.$result)) {
56+
return $result;
57+
}
58+
59+
unset($phpunitDistFiles[$result]);
60+
$otherPhpunitDistFile = key($phpunitDistFiles);
61+
62+
return file_exists($rootDir.'/'.$otherPhpunitDistFile) ? $otherPhpunitDistFile : $result;
4763
}
4864

4965
public function shouldWriteFile(string $file, bool $overwrite): bool

0 commit comments

Comments
 (0)