Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove unnecessary code from the diff command #1041

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/Console/Command/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Filesystem\Path;
use Throwable;
use Webmozart\Assert\Assert;
use function array_map;
use function count;
// TODO: migrate to Safe API
use function explode;
use function is_string;
use function KevinGH\Box\check_php_settings;
use function sprintf;
use const PHP_EOL;

Expand Down Expand Up @@ -101,26 +99,9 @@ public function getConfiguration(): Configuration

public function execute(IO $io): int
{
check_php_settings($io);

$paths = self::getPaths($io);

try {
$diff = new PharDiff(...$paths);
} catch (Throwable $throwable) {
if ($io->isDebug()) {
throw $throwable;
}

$io->writeln(
sprintf(
'<error>Could not check the PHARs: %s</error>',
$throwable->getMessage(),
),
);

return ExitCode::FAILURE;
}
$diff = new PharDiff(...$paths);

$result1 = $this->compareArchives($diff, $io);
$result2 = $this->compareContents($diff, $io);
Expand Down
8 changes: 3 additions & 5 deletions tests/Console/Command/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,16 @@ public function test_it_cannot_compare_non_existent_files(): void

public function test_it_cannot_compare_a_non_phar_files(): void
{
$this->expectException(InvalidPhar::class);
$this->expectExceptionMessageMatches('/^Could not create a Phar or PharData instance for the file.+not\-a\-phar\.phar.+$/');

$this->commandTester->execute(
[
'command' => 'diff',
'pharA' => realpath(self::FIXTURES_DIR.'/simple-phar-foo.phar'),
'pharB' => realpath(self::FIXTURES_DIR.'/not-a-phar.phar'),
],
);

$expected = '/^Could not check the PHARs: Could not create a Phar or PharData instance for the file .+$/';

self::assertMatchesRegularExpression($expected, $this->commandTester->getDisplay(true));
self::assertSame(1, $this->commandTester->getStatusCode());
}

public function test_it_can_compare_phar_files_without_the_phar_extension(): void
Expand Down
Loading