Skip to content

Commit

Permalink
Helpers: removed DynamicParameter from error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 17, 2023
1 parent 0462f01 commit 6b8ec6c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Schema/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?string
*/
public static function formatValue($value): string
{
if (is_object($value)) {
if ($value instanceof DynamicParameter) {
return 'dynamic';
} elseif (is_object($value)) {
return 'object ' . get_class($value);
} elseif (is_string($value)) {
return "'" . Nette\Utils\Strings::truncate($value, 15, '...') . "'";
Expand Down
5 changes: 5 additions & 0 deletions tests/Schema/Expect.scalars.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ test('', function () {
checkValidationErrors(function () use ($schema) {
(new Processor)->process($schema, []);
}, ['The item expects to be scalar, array given.']);

checkValidationErrors(function () use ($schema) {
(new Processor)->process($schema, new class implements Nette\Schema\DynamicParameter {
});
}, ['The item expects to be scalar, dynamic given.']);
});


Expand Down
2 changes: 2 additions & 0 deletions tests/Schema/Helpers.formatValue().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Assert::same("'hello'", Helpers::formatValue('hello'));
Assert::same("'nettenettene...'", Helpers::formatValue(str_repeat('nette', 100)));
Assert::same('array', Helpers::formatValue([1, 2]));
Assert::same('object stdClass', Helpers::formatValue(new stdClass));
Assert::same('dynamic', Helpers::formatValue(new class implements Nette\Schema\DynamicParameter {
}));

0 comments on commit 6b8ec6c

Please sign in to comment.