Skip to content

Commit

Permalink
adding tests for valid and not valid json with a given schema
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Jun 24, 2024
1 parent 222b65a commit 9836243
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Traits/ValidableBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function validateJsonWithSchema(string $schemaJson): bool
$schema =
Schema::import(json_decode($schemaJson));
$schema->in($this->toJsonObject());
} catch (\Exception $e) {
var_dump($e);
} catch (\Exception) {
//echo $e->getMessage();
return false;
}
return true;
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Traits/ValidableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@
function () use ($fruitsArray, $schemaJson): void {
$data = Block::make($fruitsArray);
expect($data->validateJsonWithSchema($schemaJson))->toBeTrue();

$schemaBlock = Block::fromJsonString($schemaJson);
$schemaBlock->set("items.properties.rating.type", "integer");
expect($data->validateJsonWithSchema($schemaBlock->toJson()))->toBeFalse();
},
);

0 comments on commit 9836243

Please sign in to comment.