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 the extract command #435

Merged
merged 1 commit into from
Sep 21, 2019
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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