Skip to content

Commit

Permalink
Merge pull request #13 from arturskonfino/arturskonfino-patch-1
Browse files Browse the repository at this point in the history
Fixed a bug with unexpected "action" key
  • Loading branch information
moufmouf committed Sep 9, 2022
2 parents c5d1580 + e57120d commit 1e57e34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/AssetOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/unitTests/AssetOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 1e57e34

Please sign in to comment.