Skip to content

Commit

Permalink
fix: Remove unnecessary code from the diff command (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Oct 9, 2023
1 parent 14cf228 commit d65001c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
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

0 comments on commit d65001c

Please sign in to comment.