Skip to content

Commit c1dd55f

Browse files
Closes #4453
1 parent 880ecb6 commit c1dd55f

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

ChangeLog-9.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes of the PHPUnit 9.3 release series are documented in this fil
66

77
### Fixed
88

9+
* [#4453](https://github.com/sebastianbergmann/phpunit/issues/4453): `--migrate-configuration` can only migrate `phpunit.xml` or `phpunit.xml.dist`
910
* [#4454](https://github.com/sebastianbergmann/phpunit/issues/4454): "Migration failed" message shown when trying to migrate XML configuration file that does not need migration
1011

1112
## [9.3.9] - 2020-09-11

src/TextUI/Command.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ protected function handleArguments(array $argv): void
232232
$this->generateConfiguration();
233233
}
234234

235-
if ($arguments->hasMigrateConfiguration() && $arguments->migrateConfiguration()) {
236-
$this->migrateConfiguration();
237-
}
238-
239235
if ($arguments->hasAtLeastVersion()) {
240236
if (version_compare(Version::id(), $arguments->atLeastVersion(), '>=')) {
241237
exit(TestRunner::SUCCESS_EXIT);
@@ -324,6 +320,16 @@ protected function handleArguments(array $argv): void
324320
}
325321
}
326322

323+
if ($arguments->hasMigrateConfiguration() && $arguments->migrateConfiguration()) {
324+
if (!isset($this->arguments['configuration'])) {
325+
print 'No configuration file found to migrate.' . PHP_EOL;
326+
327+
exit(TestRunner::EXCEPTION_EXIT);
328+
}
329+
330+
$this->migrateConfiguration(realpath($this->arguments['configuration']));
331+
}
332+
327333
if (isset($this->arguments['configuration'])) {
328334
try {
329335
$this->arguments['configurationObject'] = (new Loader)->load($this->arguments['configuration']);
@@ -770,20 +776,10 @@ private function generateConfiguration(): void
770776
exit(TestRunner::SUCCESS_EXIT);
771777
}
772778

773-
private function migrateConfiguration(): void
779+
private function migrateConfiguration(string $filename): void
774780
{
775781
$this->printVersionString();
776782

777-
if (file_exists('phpunit.xml')) {
778-
$filename = realpath('phpunit.xml');
779-
} elseif (file_exists('phpunit.xml.dist')) {
780-
$filename = realpath('phpunit.xml.dist');
781-
} else {
782-
print 'No configuration file found in ' . getcwd() . PHP_EOL;
783-
784-
exit(TestRunner::EXCEPTION_EXIT);
785-
}
786-
787783
if (!(new SchemaDetector)->detect($filename)->detected()) {
788784
print $filename . ' does not need to be migrated.' . PHP_EOL;
789785

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Configuration migration from PHPUnit 8.5 format works with custom filename
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][1] = '--configuration';
6+
$_SERVER['argv'][2] = 'custom.xml';
7+
$_SERVER['argv'][3] = '--migrate-configuration';
8+
9+
chdir(sys_get_temp_dir());
10+
copy(__DIR__ . '/migration-from-85/phpunit-8.5.xml', 'custom.xml');
11+
12+
require __DIR__ . '/../../bootstrap.php';
13+
14+
PHPUnit\TextUI\Command::main();
15+
--EXPECTF--
16+
PHPUnit %s by Sebastian Bergmann and contributors.
17+
18+
Created backup: %scustom.xml.bak
19+
Migrated configuration: %scustom.xml
20+
--CLEAN--
21+
<?php declare(strict_types=1);
22+
unlink(sys_get_temp_dir() . '/custom.xml');
23+
unlink(sys_get_temp_dir() . '/custom.xml.bak');

0 commit comments

Comments
 (0)