From 4f61e5123a58b0aa9ebf0e653cb7f97b5db2f8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sun, 22 Oct 2023 00:45:41 +0200 Subject: [PATCH] feat: Add the PHAR timestamp to the info command (#1104) --- src/Console/Command/Info.php | 4 +++ src/Console/PharInfoRenderer.php | 1 + tests/Console/Command/InfoTest.php | 32 ++++++++++++++++++ tests/Phar/PharMetaTest.php | 53 +++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/Console/Command/Info.php b/src/Console/Command/Info.php index d2780910c..5d4040fae 100644 --- a/src/Console/Command/Info.php +++ b/src/Console/Command/Info.php @@ -212,6 +212,10 @@ private static function showPharMeta(PharInfo $pharInfo, IO $io): void $io->newLine(); + PharInfoRenderer::renderTimestamp($pharInfo, $io); + + $io->newLine(); + PharInfoRenderer::renderContentsSummary($pharInfo, $io); } diff --git a/src/Console/PharInfoRenderer.php b/src/Console/PharInfoRenderer.php index d2df554a9..b0fe51c35 100644 --- a/src/Console/PharInfoRenderer.php +++ b/src/Console/PharInfoRenderer.php @@ -14,6 +14,7 @@ namespace KevinGH\Box\Console; +use DateTimeImmutable; use Fidry\Console\Input\IO; use KevinGH\Box\NotInstantiable; use KevinGH\Box\Phar\CompressionAlgorithm; diff --git a/tests/Console/Command/InfoTest.php b/tests/Console/Command/InfoTest.php index 31c46eda5..81b4913f1 100644 --- a/tests/Console/Command/InfoTest.php +++ b/tests/Console/Command/InfoTest.php @@ -105,6 +105,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680285013 (2023-03-31T17:50:13+00:00) + Contents: 1 file (6.62KB) // Use the --list|-l option to list the content of the PHAR. @@ -130,6 +132,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1559807994 (2019-06-06T07:59:54+00:00) + Contents: 2 files (6.61KB) // Use the --list|-l option to list the content of the PHAR. @@ -154,6 +158,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680284754 (2023-03-31T17:45:54+00:00) + Contents: 1 file (2.00KB) // Use the --list|-l option to list the content of the PHAR. @@ -178,6 +184,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680284754 (2023-03-31T17:45:54+00:00) + Contents: 1 file (2.00KB) sample.txt [NONE] - 13.00B @@ -200,6 +208,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1509920675 (2017-11-05T22:24:35+00:00) + Contents: 1 file (2.56KB) // Use the --list|-l option to list the content of the PHAR. @@ -225,6 +235,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) // Use the --list|-l option to list the content of the PHAR. @@ -251,6 +263,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B .hidden-file [NONE] - 0.00B @@ -293,6 +307,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B dir0/ @@ -338,6 +354,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B .hidden-file [NONE] - 0.00B @@ -367,6 +385,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B dir0/ @@ -398,6 +418,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B .hidden-file [NONE] - 0.00B @@ -434,6 +456,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B dir0/fileA [NONE] - 0.00B @@ -473,6 +497,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B .hidden-file [NONE] - 0.00B @@ -510,6 +536,8 @@ public static function inputProvider(): iterable Metadata: None + Timestamp: 1680645848 (2023-04-04T22:04:08+00:00) + Contents: 13 files (7.09KB) fileX [NONE] - 0.00B dir0/fileA [NONE] - 0.00B @@ -553,6 +581,8 @@ public static function inputProvider(): iterable 'test' => 123, ) + Timestamp: 1527142573 (2018-05-24T06:16:13+00:00) + Contents: 3 files (6.75KB) a/ bar.php [BZ2] - 60.00B @@ -586,6 +616,8 @@ public static function inputProvider(): iterable 'test' => 123, ) + Timestamp: 1527142573 (2018-05-24T06:16:13+00:00) + Contents: 3 files (6.75KB) b/ beta/ diff --git a/tests/Phar/PharMetaTest.php b/tests/Phar/PharMetaTest.php index 7dde21c9a..7c3d1b821 100644 --- a/tests/Phar/PharMetaTest.php +++ b/tests/Phar/PharMetaTest.php @@ -14,6 +14,7 @@ namespace KevinGH\Box\Phar; +use KevinGH\Box\Platform; use Phar; use PHPUnit\Framework\TestCase; use function rtrim; @@ -402,25 +403,45 @@ public static function pharProvider(): iterable } if (extension_loaded('zlib')) { - yield 'ZIP compressed simple tar' => [ - self::FIXTURES_DIR.'/../phar/simple.zip', - null, - new PharMeta( - CompressionAlgorithm::NONE, - null, + yield 'ZIP compressed simple tar' => Platform::isOSX() + ? [ + self::FIXTURES_DIR.'/../phar/simple.zip', null, + new PharMeta( + CompressionAlgorithm::NONE, + null, + null, + null, + null, + 1680284660, + null, + [ + 'sample.txt' => [ + 'compression' => CompressionAlgorithm::GZ, + 'compressedSize' => 15, + ], + ], + ), + ] + : [ + self::FIXTURES_DIR.'/../phar/simple.zip', null, - null, - 1680284660, - null, - [ - 'sample.txt' => [ - 'compression' => CompressionAlgorithm::GZ, - 'compressedSize' => 15, + new PharMeta( + CompressionAlgorithm::NONE, + null, + null, + null, + null, + 1680291860, + null, + [ + 'sample.txt' => [ + 'compression' => CompressionAlgorithm::GZ, + 'compressedSize' => 15, + ], ], - ], - ), - ]; + ), + ]; } if (extension_loaded('bz2')) {