Skip to content

Commit b94b957

Browse files
committed
Add comprehensive unit tests for MAML recipes and fix schema validation issues
1 parent 03f2201 commit b94b957

3 files changed

Lines changed: 746 additions & 32 deletions

File tree

src/Import/MamlRecipe.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ private function schema(): SchemaType
7878
]);
7979

8080
$upload = S::object([
81-
'src' => S::union(S::string(), S::arrayOf(S::string())),
82-
'dest' => S::string(),
81+
'upload' => S::object([
82+
'src' => S::union(S::string(), S::arrayOf(S::string())),
83+
'dest' => S::string(),
84+
]),
8385
]);
8486

8587
$download = S::object([
86-
'src' => S::string(),
87-
'dest' => S::string(),
88+
'download' => S::object([
89+
'src' => S::string(),
90+
'dest' => S::string(),
91+
]),
8892
]);
8993

9094
$taskConfig = S::object([
@@ -274,7 +278,7 @@ protected function tasks(Property $property): void
274278
foreach ($tasks->properties as $task) {
275279
$name = $task->key->value;
276280
$value = $task->value;
277-
$desc = trim(implode('\n', array_map(fn($comment) => $comment->value, $task->leadingComments)));
281+
$desc = trim(implode("\n", array_map(fn($comment) => $comment->value, $task->leadingComments)));
278282
if (!$value instanceof ArrayNode) {
279283
$this->throwException('Task must be an array', $value->span);
280284
}
@@ -315,6 +319,12 @@ private function createTask(string $name, ArrayNode $array, string $desc)
315319

316320
foreach ($object->properties as $property) {
317321
$key = $property->key->value;
322+
323+
if (in_array($key, ['desc', 'once', 'hidden', 'limit', 'select'])) {
324+
$task->$key($step[$key]);
325+
continue;
326+
}
327+
318328
$prev = $body;
319329

320330
$body = match ($key) {
@@ -365,8 +375,8 @@ private function createTask(string $name, ArrayNode $array, string $desc)
365375
$prev();
366376
try {
367377
upload(
368-
$step['src'],
369-
$step['dest'],
378+
$step['upload']['src'],
379+
$step['upload']['dest'],
370380
);
371381
} catch (\Throwable $e) {
372382
$this->wrapException($e, $property->span);
@@ -376,14 +386,13 @@ private function createTask(string $name, ArrayNode $array, string $desc)
376386
$prev();
377387
try {
378388
download(
379-
$step['src'],
380-
$step['dest'],
389+
$step['download']['src'],
390+
$step['download']['dest'],
381391
);
382392
} catch (\Throwable $e) {
383393
$this->wrapException($e, $property->span);
384394
}
385395
},
386-
'desc', 'once', 'hidden', 'limit', 'select' => $task->$key($step[$key]),
387396
default => $body,
388397
};
389398
}

tests/src/Import/ImportTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ public function tearDown(): void
2525
Deployer::get()->output = $this->previousOutput;
2626
}
2727

28-
public function testCanOneOverrideStaticMethod(): void
29-
{
30-
$extendedImporter = new class extends Import {
31-
public static $config = [];
32-
33-
protected static function config(array $config)
34-
{
35-
static::$config = $config;
36-
}
37-
};
38-
39-
$data = <<<EOL
40-
config:
41-
foo: bar
42-
# test.yaml
43-
EOL;
44-
45-
$extendedImporter::import("data:text/yaml,$data");
46-
47-
static::assertSame(['foo' => 'bar'], $extendedImporter::$config);
48-
}
49-
5028
public function testImporterIgnoresYamlHiddenKeys(): void
5129
{
5230
$data = <<<EOL

0 commit comments

Comments
 (0)