Skip to content

Commit

Permalink
Use all instead of toArray for a more compact format
Browse files Browse the repository at this point in the history
The array keys provide no additional information
  • Loading branch information
caendesilva committed Jan 18, 2023
1 parent 50c3260 commit 5bb0c74
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public function validate(): void
public function errors(): array
{
return [
'schema' => $this->schemaValidator->errors()->toArray(),
'fields' => $this->fieldValidators->map(fn (Validator $validator): array => $validator->errors()->toArray())->toArray(),
'schema' => $this->schemaValidator->errors()->all(),
'fields' => $this->fieldValidators->map(fn (Validator $validator): array => $validator->errors()->all())->all(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Hyde\Hyde;
use Hyde\Publications\Actions\ValidatesPublicationSchema;
use Hyde\Publications\PublicationService;
use function implode;
use InvalidArgumentException;
use function json_encode;
use LaravelZero\Framework\Commands\Command;
Expand Down Expand Up @@ -90,7 +89,7 @@ protected function displayResults(): void
} else {
$this->line(sprintf(' <fg=red>Found %s top-level schema errors:</>', count($schemaErrors)));
foreach ($schemaErrors as $error) {
$this->line(sprintf(' <fg=red>%s</> <comment>%s</comment>', self::CROSS_MARK, implode(' ', $error)));
$this->line(sprintf(' <fg=red>%s</> <comment>%s</comment>', self::CROSS_MARK, $error));
}
}

Expand All @@ -103,8 +102,7 @@ protected function displayResults(): void
foreach ($schemaFields as $fieldNumber => $fieldErrors) {
$this->line(sprintf(' <fg=cyan>Field #%s:</>', $fieldNumber + 1));
foreach ($fieldErrors as $error) {
$this->line(sprintf(' <fg=red>%s</> <comment>%s</comment>', self::CROSS_MARK,
implode(' ', $error)));
$this->line(sprintf(' <fg=red>%s</> <comment>%s</comment>', self::CROSS_MARK, $error));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,46 +235,24 @@ public function testMultipleTypesWithJsonOutput()
]
},
"test-publication-2": {
"schema": {
"name": [
"schema": [
"The name must be a string.",
"The canonical field must be a string.",
"The detail template must be a string.",
"The list template must be a string.",
"The sort field must be a string.",
"The sort ascending field must be true or false.",
"The directory field is prohibited."
],
"fields": [
[
"The type must be a string.",
"The name must be a string."
],
"canonicalField": [
"The canonical field must be a string."
],
"detailTemplate": [
"The detail template must be a string."
],
"listTemplate": [
"The list template must be a string."
],
"sortField": [
"The sort field must be a string."
],
"sortAscending": [
"The sort ascending field must be true or false."
],
"directory": [
"The directory field is prohibited."
[
"The type field is required.",
"The name field is required."
]
},
"fields": [
{
"type": [
"The type must be a string."
],
"name": [
"The name must be a string."
]
},
{
"type": [
"The type field is required."
],
"name": [
"The name field is required."
]
}
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ public function testValidateSchemaFileWithInvalidDataBuffered()

$this->assertSame([
'schema' => [
'name' => ['The name must be a string.'],
'canonicalField' => ['The canonical field must be a string.'],
'detailTemplate' => ['The detail template must be a string.'],
'listTemplate' => ['The list template must be a string.'],
'sortField' => ['The sort field must be a string.'],
'sortAscending' => ['The sort ascending field must be true or false.'],
'directory' => ['The directory field is prohibited.'],
'The name must be a string.',
'The canonical field must be a string.',
'The detail template must be a string.',
'The list template must be a string.',
'The sort field must be a string.',
'The sort ascending field must be true or false.',
'The directory field is prohibited.',
],
'fields' => [[
'type' => ['The type must be a string.'],
'name' => ['The name must be a string.'],
'The type must be a string.',
'The name must be a string.',
], [
'type' => ['The type field is required.'],
'name' => ['The name field is required.'],
'The type field is required.',
'The name field is required.',
]],
], $errors);
}
Expand Down

0 comments on commit 5bb0c74

Please sign in to comment.