From 3131495488ef16533d9218db0c51f04d4af69232 Mon Sep 17 00:00:00 2001 From: Bruce Chase Date: Mon, 14 Jan 2019 15:06:04 -0800 Subject: [PATCH] ArraysTest for array items with enum validation Tests number, integer and string array items types that have enums of acceptable values --- tests/Constraints/ArraysTest.php | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index dac14358..63b97bf1 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -71,6 +71,51 @@ public function getInvalidTests() } } }' + ), + array( // Test array items.enum where type string fail validation if value(s) is/are not in items.enum + '{"data": ["a", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' + ), + array( // Test array items.enum where type integer fail validation if value(s) is/are not in items.enum + '{"data": [1, 2]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "integer", + "enum": [2, 3] + } + } + } + }' + ), + array( // Test array items.enum where type number fail validation if value(s) is/are not in items.enum + '{"data": [1.25, 2.25]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "number", + "enum": [1.25, 2] + } + } + } + }' ) ); } @@ -168,6 +213,51 @@ public function getValidTests() } } }' + ), + array( // Test array items.enum where type string passes validation if value(s) is/are in items.enum + '{"data": ["c", "c", "b"]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string", + "enum": ["b", "c"] + } + } + } + }' + ), + array( // Test array items.enum where type integer passes validation if value(s) is/are in items.enum + '{"data": [1, 1, 2]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "integer", + "enum": [1, 2] + } + } + } + }' + ), + array( // Test array items.enum where type number passes validation if value(s) is/are in items.enum + '{"data": [1.25, 1.25, 2.25]}', + '{ + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "number", + "enum": [1.25, 2.25] + } + } + } + }' ) ); }