From e8168fbe69ac9d7f01416160f0ae0e5af209bae8 Mon Sep 17 00:00:00 2001 From: Kolyunya Date: Mon, 2 Aug 2021 00:16:39 +0300 Subject: [PATCH] Add a failing test for JsonType assert --- tests/unit/Codeception/Module/RestTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/Codeception/Module/RestTest.php b/tests/unit/Codeception/Module/RestTest.php index 7e025e3..f0d9fc9 100644 --- a/tests/unit/Codeception/Module/RestTest.php +++ b/tests/unit/Codeception/Module/RestTest.php @@ -493,6 +493,21 @@ public function testJsonTypeMatchesWithJsonPath() $this->module->dontSeeResponseMatchesJsonType(['id' => 'integer'], '$.users[0]'); } + public function testJsonTypeMatchesWithJsonPathAndPotentiallyEmptyArrays() + { + // Passes when all users have non-empty roles. + $this->setStubResponse('{"users": [{"id": 1, "roles": [{"name": "admin"}]}]}'); + $this->module->seeResponseMatchesJsonType(['name' => 'string'], '$.users.*.roles.*'); + + // Passes when at least one user has non-empty roles. + $this->setStubResponse('{"users": [{"id": 1, "roles": [{"name": "admin"}]}, {"id": 2, "roles": []}]}'); + $this->module->seeResponseMatchesJsonType(['name' => 'string'], '$.users.*.roles.*'); + + // Fails when all users have empty roles. + $this->setStubResponse('{"users": [{"id": 1, "roles": []}]}'); + $this->module->seeResponseMatchesJsonType(['name' => 'string'], '$.users.*.roles.*'); + } + public function testMatchJsonTypeFailsWithNiceMessage() { $this->setStubResponse('{"xxx": "yyy", "user_id": 1}');