镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/unit/Codeception/Module/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}');
Expand Down