diff --git a/fixtures/extract/corrupted.phar b/fixtures/extract/corrupted.phar deleted file mode 100644 index 90f0a5359..000000000 Binary files a/fixtures/extract/corrupted.phar and /dev/null differ diff --git a/fixtures/extract/incorrect-key-openssl.phar b/fixtures/extract/incorrect-key-openssl.phar deleted file mode 100644 index a2cd9b8d0..000000000 Binary files a/fixtures/extract/incorrect-key-openssl.phar and /dev/null differ diff --git a/fixtures/extract/incorrect-key-openssl.phar.pubkey b/fixtures/extract/incorrect-key-openssl.phar.pubkey deleted file mode 100644 index e69de29bb..000000000 diff --git a/fixtures/extract/invalid b/fixtures/extract/invalid deleted file mode 100644 index e69de29bb..000000000 diff --git a/fixtures/extract/invalid.phar b/fixtures/extract/invalid.phar deleted file mode 100644 index e69de29bb..000000000 diff --git a/fixtures/extract/openssl-no-pubkey.phar b/fixtures/extract/openssl-no-pubkey.phar deleted file mode 100644 index a2cd9b8d0..000000000 Binary files a/fixtures/extract/openssl-no-pubkey.phar and /dev/null differ diff --git a/src/Console/Command/Extract.php b/src/Console/Command/Extract.php index 7bee510cc..57f6d82ee 100644 --- a/src/Console/Command/Extract.php +++ b/src/Console/Command/Extract.php @@ -18,15 +18,13 @@ use Fidry\Console\Command\Configuration; use Fidry\Console\ExitCode; use Fidry\Console\Input\IO; -use KevinGH\Box\Pharaoh\InvalidPhar; +use KevinGH\Box\Phar\PharFactory; use KevinGH\Box\Pharaoh\Pharaoh; use ParagonIE\ConstantTime\Hex; use Phar; -use PharData; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Question\ConfirmationQuestion; use Throwable; -use UnexpectedValueException; use function file_exists; use function KevinGH\Box\check_php_settings; use function KevinGH\Box\FileSystem\copy; @@ -145,7 +143,7 @@ private static function dumpPhar(string $file, string $tmpDir): string copy($pubkey, $tmpPubkey, true); } - $phar = self::createPhar($file, $tmpFile); + $phar = PharFactory::create($tmpFile); $phar->extractTo($tmpDir); } catch (Throwable $throwable) { @@ -186,13 +184,4 @@ private static function getExtension(string $file): string return '' === $extension ? '.phar' : $extension; } - - private static function createPhar(string $file, string $tmpFile): Phar|PharData - { - try { - return new Phar($tmpFile); - } catch (UnexpectedValueException $cannotCreatePhar) { - throw InvalidPhar::forPhar($file, $cannotCreatePhar); - } - } } diff --git a/tests/Console/Command/ExtractTest.php b/tests/Console/Command/ExtractTest.php index 9c3a3a156..db7c18037 100644 --- a/tests/Console/Command/ExtractTest.php +++ b/tests/Console/Command/ExtractTest.php @@ -208,11 +208,8 @@ public static function confirmationQuestionProvider(): iterable /** * @dataProvider invalidPharPath */ - public function test_it_cannot_extract_an_invalid_phar( - string $pharPath, - string $exceptionClassName, - string $expectedExceptionMessage, - ): void { + public function test_it_cannot_extract_an_invalid_phar(string $pharPath): void + { try { $this->commandTester->execute( [ @@ -228,48 +225,13 @@ public function test_it_cannot_extract_an_invalid_phar( // Continue } - self::assertSame( - $exceptionClassName, - $exception::class, - ); - self::assertMatchesRegularExpression( - $expectedExceptionMessage, - $exception->getMessage(), - ); - self::assertSame([], $this->collectExtractedFiles()); } public static function invalidPharPath(): iterable { - yield 'not a valid PHAR with the PHAR extension' => [ - self::FIXTURES.'/invalid.phar', - InvalidPhar::class, - '/^Could not create a Phar instance for the file/', - ]; - - yield 'not a valid PHAR without the PHAR extension' => [ - self::FIXTURES.'/invalid', - InvalidPhar::class, - '/^Could not create a Phar instance for the file/', - ]; - - yield 'corrupted PHAR (was valid; got tempered with)' => [ - self::FIXTURES.'/corrupted.phar', - InvalidPhar::class, - '/^Could not create a Phar instance for the file/', - ]; - - yield 'OpenSSL signed PHAR without a pubkey' => [ - self::FIXTURES.'/openssl-no-pubkey.phar', - InvalidPhar::class, - '/^Could not create a Phar instance for the file/', - ]; - - yield 'OpenSSL signed PHAR with incorrect pubkey' => [ - self::FIXTURES.'/incorrect-key-openssl.phar', - InvalidPhar::class, - '/^Could not create a Phar instance for the file/', + yield 'not a valid PHAR' => [ + self::FIXTURES.'/../phar/empty-pdf.pdf', ]; }