Skip to content

Commit

Permalink
Fix the extract command (#435)
Browse files Browse the repository at this point in the history
Closes #430, #428
  • Loading branch information
theofidry committed Sep 21, 2019
1 parent 846a278 commit a561fad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 52 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -7,7 +7,6 @@
!/bin/box
!/bin/box.bat
!/bin/generate_default_stub
!/bin/dump-requirements-checker.php
/dist/
/Dockerfile*
/fixtures/default_stub.php
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -291,6 +291,7 @@ requirement-checker/composer.lock: requirement-checker/composer.json

vendor: composer.lock
composer install
touch $@

vendor/bamarni: composer.lock
composer install
Expand Down Expand Up @@ -352,7 +353,7 @@ requirement-checker/tests/DisplayNormalizer.php: tests/Console/DisplayNormalizer
cat tests/Console/DisplayNormalizer.php | sed -E 's/namespace KevinGH\\Box\\Console;/namespace KevinGH\\RequirementChecker;/g' > requirement-checker/tests/DisplayNormalizer.php

.requirement-checker: requirement-checker/bin/check-requirements.phar
php bin/dump-requirements-checker.php
php bin/box extract requirement-checker/bin/check-requirements.phar .requirement-checker
touch $@

requirement-checker/actual_terminal_diff: requirement-checker/src/Terminal.php vendor/symfony/console/Terminal.php
Expand Down
19 changes: 0 additions & 19 deletions bin/dump-requirements-checker.php

This file was deleted.

15 changes: 8 additions & 7 deletions src/Console/Command/Extract.php
Expand Up @@ -20,10 +20,12 @@
use function KevinGH\Box\create_temporary_phar;
use function KevinGH\Box\FileSystem\dump_file;
use function KevinGH\Box\FileSystem\remove;
use PharFileInfo;
use function realpath;
use RecursiveIteratorIterator;
use RuntimeException;
use function sprintf;
use function strlen;
use function substr;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Throwable;
Expand Down Expand Up @@ -102,11 +104,12 @@ protected function executeCommand(IO $io): int
try {
remove($outputDir);

foreach ($box->getPhar() as $pharFile) {
/* @var PharFileInfo $pharFile */
$rootLength = strlen('phar://'.$box->getPhar()->getPath()) + 1;

foreach (new RecursiveIteratorIterator($box->getPhar()) as $file) {
dump_file(
$outputDir.'/'.$pharFile->getFilename(),
(string) $pharFile->getContent()
$outputDir.'/'.substr($file->getPathname(), $rootLength),
(string) $file->getContent()
);
}
} catch (RuntimeException $exception) {
Expand All @@ -119,8 +122,6 @@ protected function executeCommand(IO $io): int
remove($tmpFile);
}

$io->success('');

return 0;
}
}
27 changes: 3 additions & 24 deletions tests/Console/Command/ExtractTest.php
Expand Up @@ -65,16 +65,9 @@ public function test_it_can_extract_a_phar(): void

$this->assertEqualsCanonicalizing($expectedFiles, $actualFiles);

$expectedOutput = <<<'OUTPUT'
[OK]
OUTPUT;

$actual = DisplayNormalizer::removeTrailingSpaces($this->commandTester->getDisplay(true));

$this->assertSame($expectedOutput, $actual);
$this->assertSame('', $actual);
$this->assertSame(0, $this->commandTester->getStatusCode());
}

Expand All @@ -99,16 +92,9 @@ public function test_it_can_extract_a_phar_without_the_phar_extension(): void

$this->assertEqualsCanonicalizing($expectedFiles, $actualFiles);

$expectedOutput = <<<'OUTPUT'
[OK]
OUTPUT;

$actual = DisplayNormalizer::removeTrailingSpaces($this->commandTester->getDisplay(true));

$this->assertSame($expectedOutput, $actual);
$this->assertSame('', $actual);
$this->assertSame(0, $this->commandTester->getStatusCode());
}

Expand All @@ -133,16 +119,9 @@ public function test_it_can_extract_a_compressed_phar(): void

$this->assertEqualsCanonicalizing($expectedFiles, $actualFiles);

$expectedOutput = <<<'OUTPUT'
[OK]
OUTPUT;

$actual = DisplayNormalizer::removeTrailingSpaces($this->commandTester->getDisplay(true));

$this->assertSame($expectedOutput, $actual);
$this->assertSame('', $actual);
$this->assertSame(0, $this->commandTester->getStatusCode());
}

Expand Down

0 comments on commit a561fad

Please sign in to comment.