Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Oct 22, 2023
1 parent 9d96ed0 commit 5f08c1a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/Console/Command/Extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
use Fidry\FileSystem\FS;
use KevinGH\Box\Phar\InvalidPhar;
use KevinGH\Box\Phar\PharFactory;
use KevinGH\Box\Phar\PharInfo;
use KevinGH\Box\Phar\PharMeta;
use ParagonIE\ConstantTime\Hex;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Filesystem\Path;
use Throwable;
use function file_exists;
use function KevinGH\Box\check_php_settings;
Expand Down
1 change: 0 additions & 1 deletion src/Phar/PharInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

namespace KevinGH\Box\Phar;

use DateTimeImmutable;
use Fidry\FileSystem\FS;
use KevinGH\Box\Console\Command\Extract;
use OutOfBoundsException;
Expand Down
4 changes: 2 additions & 2 deletions src/Phar/PharMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
final class PharMeta
{
/**
* @param non-empty-string $stub
* @param non-empty-string|null $stub
* @param non-empty-string|null $version
* @param non-empty-string|null $normalizedMetadata
* @param non-empty-string|null $pubKeyContent
Expand All @@ -49,7 +49,7 @@ public function __construct(
public readonly CompressionAlgorithm $compression,
#[ArrayShape(['hash' => 'string', 'hash_type' => 'string'])]
public readonly ?array $signature,
public readonly string $stub,
public readonly ?string $stub,
public readonly ?string $version,
public readonly ?string $normalizedMetadata,
public readonly int $timestamp,
Expand Down
57 changes: 56 additions & 1 deletion tests/Console/Command/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,60 @@ public static function gitDiffPharsProvider(): iterable

public static function GNUDiffPharsProvider(): iterable
{
yield from self::commonDiffPharsProvider(DiffMode::GNU);
foreach (self::commonDiffPharsProvider(DiffMode::GNU) as $label => $set) {
yield $label => 'different data; same content' === $label
? [
self::FIXTURES_DIR.'/simple-phar-bar.phar',
self::FIXTURES_DIR.'/simple-phar-bar-compressed.phar',
sprintf(
<<<'OUTPUT'
// Comparing the two archives...
Archive: simple-phar-bar.phar
Archive Compression: None
Files Compression: None
Signature: SHA-1
Signature Hash: 9ADC09F73909EDF14F8A4ABF9758B6FFAD1BBC51
Metadata: None
Timestamp: 1552839827 (2019-03-17T16:23:47+00:00)
Contents: 1 file (6.64KB)
Archive: simple-phar-bar-compressed.phar
Archive Compression: None
Files Compression: GZ
Signature: SHA-1
Signature Hash: 3A388D86C91C36659A043D52C2DEB64E8848DD1A
Metadata: None
Timestamp: 1552856416 (2019-03-17T21:00:16+00:00)
Contents: 1 file (6.65KB)
<diff-expected>--- PHAR A</diff-expected>
<diff-actual>+++ PHAR B</diff-actual>
@@ @@
Archive Compression: None
<diff-expected>-Files Compression: None</diff-expected>
<diff-actual>+Files Compression: GZ</diff-actual>
Signature: SHA-1
<diff-expected>-Signature Hash: 9ADC09F73909EDF14F8A4ABF9758B6FFAD1BBC51</diff-expected>
<diff-actual>+Signature Hash: 3A388D86C91C36659A043D52C2DEB64E8848DD1A</diff-actual>
Metadata: None
<diff-expected>-Timestamp: 1552839827 (2019-03-17T16:23:47+00:00)</diff-expected>
<diff-expected>-Contents: 1 file (6.64KB)</diff-expected>
<diff-actual>+Timestamp: 1552856416 (2019-03-17T21:00:16+00:00)</diff-actual>
<diff-actual>+Contents: 1 file (6.65KB)</diff-actual>
// Comparing the two archives contents (%s diff)...
Common subdirectories: simple-phar-bar.phar/.phar and simple-phar-bar-compressed.phar/.phar

OUTPUT,
DiffMode::GNU->value,
),
ExitCode::FAILURE,
]
: $set;
}

yield 'different files' => [
self::FIXTURES_DIR.'/simple-phar-foo.phar',
Expand Down Expand Up @@ -620,6 +673,7 @@ public static function GNUDiffPharsProvider(): iterable
// Comparing the two archives contents (gnu diff)...
Common subdirectories: simple-phar-foo.phar/.phar and simple-phar-bar.phar/.phar
Only in simple-phar-bar.phar: bar.php
Only in simple-phar-foo.phar: foo.php

Expand Down Expand Up @@ -669,6 +723,7 @@ public static function GNUDiffPharsProvider(): iterable
// Comparing the two archives contents (gnu diff)...
Common subdirectories: simple-phar-bar.phar/.phar and simple-phar-baz.phar/.phar
diff --exclude=.phar_meta.json simple-phar-bar.phar/bar.php simple-phar-baz.phar/bar.php
3c3
< echo "Hello world!";
Expand Down
4 changes: 4 additions & 0 deletions tests/Console/Command/ExtractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private static function pharProvider(): iterable
);

$expectedSimplePharFiles = [
'.phar/stub.php' => $oldDefaultPharStub,
'.hidden' => 'baz',
'foo' => 'bar',
'.phar_meta.json' => $pharMeta->toJson(),
Expand All @@ -118,6 +119,7 @@ private static function pharProvider(): iterable
yield 'GZ compressed simple PHAR' => [
self::FIXTURES_DIR.'/gz-compressed-phar.phar',
[
'.phar/stub.php' => $oldDefaultPharStub,
'.hidden' => 'baz',
'foo' => 'bar',
'.phar_meta.json' => (new PharMeta(
Expand Down Expand Up @@ -149,6 +151,7 @@ private static function pharProvider(): iterable
yield 'sha512 signed PHAR' => [
self::FIXTURES_DIR.'/sha512.phar',
[
'.phar/stub.php' => $sha512Stub,
'index.php' => <<<'PHP'
<?php echo "Hello, world!\n";

Expand Down Expand Up @@ -177,6 +180,7 @@ private static function pharProvider(): iterable
yield 'OpenSSL signed PHAR' => [
self::FIXTURES_DIR.'/openssl.phar',
[
'.phar/stub.php' => $sha512Stub,
'index.php' => <<<'PHP'
<?php echo "Hello, world!\n";

Expand Down

0 comments on commit 5f08c1a

Please sign in to comment.