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)); } /** 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());