Skip to content

Commit

Permalink
[phar-io#233] Simplify UI + User interaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
MacFJA committed May 11, 2020
1 parent b777086 commit cc14a78
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 418 deletions.
2 changes: 0 additions & 2 deletions src/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ function($class) {
'phario\\phive\\gnupgverificationresult' => '/services/signature/gpg/GnupgVerificationResult.php',
'phario\\phive\\hash' => '/shared/hash/Hash.php',
'phario\\phive\\helpcommand' => '/commands/help/HelpCommand.php',
'phario\\phive\\homeauthxmlmigration' => '/services/migration/HomeAuthXmlMigration.php',
'phario\\phive\\homepharsxmlmigration' => '/services/migration/HomePharsXmlMigration.php',
'phario\\phive\\homephivexmlmigration' => '/services/migration/HomePhiveXmlMigration.php',
'phario\\phive\\httpclient' => '/shared/http/HttpClient.php',
Expand Down Expand Up @@ -160,7 +159,6 @@ function($class) {
'phario\\phive\\phiveversion' => '/shared/version/PhiveVersion.php',
'phario\\phive\\phivexmlconfig' => '/shared/config/PhiveXmlConfig.php',
'phario\\phive\\phivexmlconfigfilelocator' => '/shared/config/PhiveXmlConfigFileLocator.php',
'phario\\phive\\projectauthxmlmigration' => '/services/migration/ProjectAuthXmlMigration.php',
'phario\\phive\\projectphivexmlmigration' => '/services/migration/ProjectPhiveXmlMigration.php',
'phario\\phive\\publickey' => '/services/key/PublicKey.php',
'phario\\phive\\publickeyexception' => '/shared/exceptions/PublicKeyException.php',
Expand Down
27 changes: 8 additions & 19 deletions src/commands/migrate/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ class MigrateCommand implements Cli\Command {
/** @var MigrateCommandConfig */
private $config;

/** @var PharRegistry */
private $pharRegistry;

/** @var Cli\Output */
private $output;

/** @var PhiveXmlConfig */
private $phiveXmlConfig;
/** @var MigrationService */
private $migrationService;

Expand All @@ -34,26 +29,20 @@ public function __construct(

public function execute(): void {
if ($this->config->showStatus()) {
$migrations = $this->migrationService->getAllMigration();
$table = new ConsoleTable(['Status', 'Mandatory', 'Description']);
$migrations = $this->migrationService->getUserMigrations();
$table = new ConsoleTable(['Status', 'Description']);

foreach ($migrations as $migration) {
switch (true) {
case $migration->canMigrate():
$status = 'Not applied';

break;
case $migration->inError():
$status = 'Can\'t migrate';

break;
default:
$status = 'Migrated';
if ($migration->canMigrate()) {
$status = 'Not applied';
} elseif ($migration->inError()) {
$status = 'Can\'t migrate';
} else {
continue;
}

$table->addRow([
$status,
$migration->mustMigrate() ? 'Yes' : 'No',
$migration->getDescription()
]);
}
Expand Down
6 changes: 5 additions & 1 deletion src/services/migration/FileMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public function migrate(): void {

$this->doMigrate($this->legacy, $this->new);

$this->handleOldFile($this->getFileDescription(), $this->legacy);
if ($this->mustMigrate()) {
$this->legacy->delete();
} else {
$this->handleOldFile($this->getFileDescription(), $this->legacy);
}
}

abstract protected function doMigrate(Filename $legacy, Filename $new): void;
Expand Down
32 changes: 0 additions & 32 deletions src/services/migration/HomeAuthXmlMigration.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/services/migration/MigrationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ public function __construct(Factory $factory, Environment $environment, Cli\Inpu
*/
public function getMigrations(): array {
return [
new HomeAuthXmlMigration($this->factory->getConfig(), $this->input),
new HomePharsXmlMigration($this->factory->getConfig(), $this->input),
new HomePhiveXmlMigration($this->factory->getConfig(), $this->input),
new ProjectPhiveXmlMigration($this->environment, $this->factory->getConfig(), $this->input),
new ProjectAuthXmlMigration($this->environment, $this->factory->getConfig(), $this->input)
];
}
}
6 changes: 4 additions & 2 deletions src/services/migration/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public function ensureFitness(): void {
/**
* @return Migration[]
*/
public function getAllMigration(): array {
return $this->factory->getMigrations();
public function getUserMigrations(): array {
return \array_filter($this->factory->getMigrations(), function (Migration $migration) {
return !$migration->mustMigrate();
});
}
public function runAll(): int {
return $this->runMigrations(false);
Expand Down
32 changes: 0 additions & 32 deletions src/services/migration/ProjectAuthXmlMigration.php

This file was deleted.

3 changes: 0 additions & 3 deletions tests/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ function($class) {
'phario\\phive\\filedownloadertest' => '/unit/shared/download/FileDownloaderTest.php',
'phario\\phive\\gitawarephiveversiontest' => '/unit/shared/version/GitAwarePhiveVersionTest.php',
'phario\\phive\\githubrepositorytest' => '/unit/shared/repository/GithubRepositoryTest.php',
'phario\\phive\\githubversiontest' => '/unit/shared/version/GitHubVersionTest.php',
'phario\\phive\\gitlabrepositorytest' => '/unit/shared/repository/GitlabRepositoryTest.php',
'phario\\phive\\gnupgkeydownloadertest' => '/unit/services/key/gpg/GnupgKeyDownloaderTest.php',
'phario\\phive\\gnupgkeyimportertest' => '/unit/services/key/gpg/GnupgKeyImporterTest.php',
'phario\\phive\\gnupgsignatureverifiertest' => '/unit/services/signature/gpg/GnupgSignatureVerifierTest.php',
'phario\\phive\\gnupgverificationresulttest' => '/unit/services/signature/gpg/GnupgVerificationResultTest.php',
'phario\\phive\\helpcommandtest' => '/unit/commands/help/HelpCommandTest.php',
'phario\\phive\\homeauthxmlmigrationtest' => '/unit/services/migration/HomeAuthXmlMigrationTest.php',
'phario\\phive\\homepharsxmlmigrationtest' => '/unit/services/migration/HomePharsXmlMigrationTest.php',
'phario\\phive\\homephivexmlmigrationtest' => '/unit/services/migration/HomePhiveXmlMigrationTest.php',
'phario\\phive\\httpprogressupdatetest' => '/unit/shared/http/HttpProgressUpdateTest.php',
Expand All @@ -62,7 +60,6 @@ function($class) {
'phario\\phive\\phartest' => '/unit/shared/phar/PharTest.php',
'phario\\phive\\phivecontexttest' => '/unit/PhiveContextTest.php',
'phario\\phive\\phivexmlconfigfilelocatortest' => '/unit/shared/config/PhiveXmlConfigFileLocatorTest.php',
'phario\\phive\\projectauthxmlmigrationtest' => '/unit/services/migration/ProjectAuthXmlMigrationTest.php',
'phario\\phive\\projectphivexmlmigrationtest' => '/unit/services/migration/ProjectPhiveXmlMigrationTest.php',
'phario\\phive\\purgecommandtest' => '/unit/commands/purge/PurgeCommandTest.php',
'phario\\phive\\regressiontestbootstrap' => '/regression/RegressionTestBootstrap.php',
Expand Down
105 changes: 0 additions & 105 deletions tests/unit/services/migration/HomeAuthXmlMigrationTest.php

This file was deleted.

22 changes: 0 additions & 22 deletions tests/unit/services/migration/HomePharsXmlMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,6 @@ public function testMigrate(): void {
$this->assertStringEqualsFile(__DIR__ . '/tmp/registry.xml', '<?xml><root>Foobar</root>');
}

public function testMigrateRename(): void {
$directory = new Directory(__DIR__ . '/tmp');
$directory->file('phars.xml')->putContent('<?xml><root>Foobar</root>');

$config = $this->createPartialMock(Config::class, ['getHomeDirectory']);
$config->method('getHomeDirectory')->willReturn($directory);

$migration = new HomePharsXmlMigration($config, $this->getInputMock($this, true));

$migration->migrate();

$this->assertFileExists(__DIR__ . '/tmp/registry.xml');
$this->assertFileExists(__DIR__ . '/tmp/phars.xml.backup');

if (\method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist(__DIR__ . '/tmp/phars.xml');
} else {
$this->assertFileNotExists(__DIR__ . '/tmp/phars.xml');
}
$this->assertStringEqualsFile(__DIR__ . '/tmp/registry.xml', '<?xml><root>Foobar</root>');
}

private function createMigration(array $existingFiles): HomePharsXmlMigration {
$config = $this->createPartialMock(Config::class, ['getHomeDirectory']);
$config->method('getHomeDirectory')->willReturn($this->getDirectoryWithFileMock($this, $existingFiles));
Expand Down
22 changes: 0 additions & 22 deletions tests/unit/services/migration/HomePhiveXmlMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,6 @@ public function testMigrate(): void {
$this->assertStringEqualsFile(__DIR__ . '/tmp/global.xml', '<?xml><root>Foobar</root>');
}

public function testMigrateRename(): void {
$directory = new Directory(__DIR__ . '/tmp');
$directory->file('phive.xml')->putContent('<?xml><root>Foobar</root>');

$config = $this->createPartialMock(Config::class, ['getHomeDirectory']);
$config->method('getHomeDirectory')->willReturn($directory);

$migration = new HomePhiveXmlMigration($config, $this->getInputMock($this, true));

$migration->migrate();

$this->assertFileExists(__DIR__ . '/tmp/global.xml');
$this->assertFileExists(__DIR__ . '/tmp/phive.xml.backup');

if (\method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist(__DIR__ . '/tmp/phive.xml');
} else {
$this->assertFileNotExists(__DIR__ . '/tmp/phive.xml');
}
$this->assertStringEqualsFile(__DIR__ . '/tmp/global.xml', '<?xml><root>Foobar</root>');
}

private function createMigration(array $existingFiles): HomePhiveXmlMigration {
$config = $this->createPartialMock(Config::class, ['getHomeDirectory']);
$config->method('getHomeDirectory')->willReturn($this->getDirectoryWithFileMock($this, $existingFiles));
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/services/migration/MigrationMocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ private function getFileMissingMock(TestCase $testCase): Filename {
return $file;
}

private function getOutputMock(TestCase $testCase): Cli\Output {
return $testCase->createMock(Cli\Output::class);
}

private function getDirectoryWithFileMock(TestCase $testCase, array $files): Directory {
$directory = $testCase->createMock(Directory::class);
$directory->method('file')->willReturnCallback(function ($file) use ($files, $testCase) {
Expand Down
Loading

0 comments on commit cc14a78

Please sign in to comment.