Skip to content

Commit

Permalink
Closes #4453
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 12, 2020
1 parent 880ecb6 commit c1dd55f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions ChangeLog-9.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 9.3 release series are documented in this fil

### Fixed

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

## [9.3.9] - 2020-09-11
Expand Down
26 changes: 11 additions & 15 deletions src/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ protected function handleArguments(array $argv): void
$this->generateConfiguration();
}

if ($arguments->hasMigrateConfiguration() && $arguments->migrateConfiguration()) {
$this->migrateConfiguration();
}

if ($arguments->hasAtLeastVersion()) {
if (version_compare(Version::id(), $arguments->atLeastVersion(), '>=')) {
exit(TestRunner::SUCCESS_EXIT);
Expand Down Expand Up @@ -324,6 +320,16 @@ protected function handleArguments(array $argv): void
}
}

if ($arguments->hasMigrateConfiguration() && $arguments->migrateConfiguration()) {
if (!isset($this->arguments['configuration'])) {
print 'No configuration file found to migrate.' . PHP_EOL;

exit(TestRunner::EXCEPTION_EXIT);
}

$this->migrateConfiguration(realpath($this->arguments['configuration']));
}

if (isset($this->arguments['configuration'])) {
try {
$this->arguments['configurationObject'] = (new Loader)->load($this->arguments['configuration']);
Expand Down Expand Up @@ -770,20 +776,10 @@ private function generateConfiguration(): void
exit(TestRunner::SUCCESS_EXIT);
}

private function migrateConfiguration(): void
private function migrateConfiguration(string $filename): void
{
$this->printVersionString();

if (file_exists('phpunit.xml')) {
$filename = realpath('phpunit.xml');
} elseif (file_exists('phpunit.xml.dist')) {
$filename = realpath('phpunit.xml.dist');
} else {
print 'No configuration file found in ' . getcwd() . PHP_EOL;

exit(TestRunner::EXCEPTION_EXIT);
}

if (!(new SchemaDetector)->detect($filename)->detected()) {
print $filename . ' does not need to be migrated.' . PHP_EOL;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Configuration migration from PHPUnit 8.5 format works with custom filename
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][1] = '--configuration';
$_SERVER['argv'][2] = 'custom.xml';
$_SERVER['argv'][3] = '--migrate-configuration';

chdir(sys_get_temp_dir());
copy(__DIR__ . '/migration-from-85/phpunit-8.5.xml', 'custom.xml');

require __DIR__ . '/../../bootstrap.php';

PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Created backup: %scustom.xml.bak
Migrated configuration: %scustom.xml
--CLEAN--
<?php declare(strict_types=1);
unlink(sys_get_temp_dir() . '/custom.xml');
unlink(sys_get_temp_dir() . '/custom.xml.bak');

0 comments on commit c1dd55f

Please sign in to comment.