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}');