Skip to content

Commit 1e57e34

Browse files
authored
Merge pull request #13 from arturskonfino/arturskonfino-patch-1
Fixed a bug with unexpected "action" key
2 parents c5d1580 + e57120d commit 1e57e34

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/AssetOperation.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,19 @@ public static function buildFromArray(array $array, string $package, string $pac
9494
} else {
9595
$metadata = [];
9696
}
97+
98+
if (isset($array['action'])) {
99+
$action = $array['action'];
100+
unset($array['action']);
101+
} else {
102+
$action = self::ADD;
103+
}
97104

98105
if (!empty($array)) {
99106
throw new JsonException(sprintf('Unexpected key(s) in discovery.json from package %s: "%s"', $package, implode(', ', array_keys($array))));
100107
}
101108

102-
return new self(self::ADD, new Asset($value, $package, $packageDir, $priority, $metadata));
109+
return new self($action, new Asset($value, $package, $packageDir, $priority, $metadata));
103110
}
104111

105112
/**

tests/unitTests/AssetOperationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function testBuildFromArray()
2929
'priority' => 99,
3030
'metadata' => [
3131
'foo' => 'bar'
32-
]
32+
],
33+
'action' => 'add'
3334
], 'bar/baz', 'vendor/bar/baz');
3435
$this->assertSame(AssetOperation::ADD, $assetOperation->getOperation());
3536
$this->assertSame('foo', $assetOperation->getAsset()->getValue());

0 commit comments

Comments
 (0)