From 9836243f751184ee5b1e6acb5584253f4896ad72 Mon Sep 17 00:00:00 2001 From: Roberto Butti Date: Mon, 24 Jun 2024 07:50:42 +0200 Subject: [PATCH] adding tests for valid and not valid json with a given schema --- src/Traits/ValidableBlock.php | 4 ++-- tests/Unit/Traits/ValidableTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Traits/ValidableBlock.php b/src/Traits/ValidableBlock.php index a4370a7..88624c7 100644 --- a/src/Traits/ValidableBlock.php +++ b/src/Traits/ValidableBlock.php @@ -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; diff --git a/tests/Unit/Traits/ValidableTest.php b/tests/Unit/Traits/ValidableTest.php index fb763ed..b423512 100644 --- a/tests/Unit/Traits/ValidableTest.php +++ b/tests/Unit/Traits/ValidableTest.php @@ -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(); }, );