From f43edeb5a96d0baeca1d0a47939812abc8db4338 Mon Sep 17 00:00:00 2001 From: arturskonfino <68226561+arturskonfino@users.noreply.github.com> Date: Tue, 17 Nov 2020 13:03:29 +0200 Subject: [PATCH 1/2] Fixed a bug with unexpected "action" key --- src/AssetOperation.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AssetOperation.php b/src/AssetOperation.php index 08ce29a..ed3c9bd 100644 --- a/src/AssetOperation.php +++ b/src/AssetOperation.php @@ -94,12 +94,19 @@ public static function buildFromArray(array $array, string $package, string $pac } else { $metadata = []; } + + if (isset($array['action'])) { + $action = $array['action']; + unset($array['action']); + } else { + $action = self::ADD; + } if (!empty($array)) { throw new JsonException(sprintf('Unexpected key(s) in discovery.json from package %s: "%s"', $package, implode(', ', array_keys($array)))); } - return new self(self::ADD, new Asset($value, $package, $packageDir, $priority, $metadata)); + return new self($action, new Asset($value, $package, $packageDir, $priority, $metadata)); } /** From e57120d16c0adcef25115a3f676ac4ca705dede3 Mon Sep 17 00:00:00 2001 From: Arturs Konfino <68226561+arturskonfino@users.noreply.github.com> Date: Sat, 21 Nov 2020 14:42:15 +0200 Subject: [PATCH 2/2] Updated unit tests --- tests/unitTests/AssetOperationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unitTests/AssetOperationTest.php b/tests/unitTests/AssetOperationTest.php index 4c5fc7d..0d9b917 100644 --- a/tests/unitTests/AssetOperationTest.php +++ b/tests/unitTests/AssetOperationTest.php @@ -29,7 +29,8 @@ public function testBuildFromArray() 'priority' => 99, 'metadata' => [ 'foo' => 'bar' - ] + ], + 'action' => 'add' ], 'bar/baz', 'vendor/bar/baz'); $this->assertSame(AssetOperation::ADD, $assetOperation->getOperation()); $this->assertSame('foo', $assetOperation->getAsset()->getValue());