Codeception seeResponseMatchesJsonType 方法未正确验证字段
Codeception seeResponseMatchesJsonType method isn't validate fields correctly
我有 API 测试
public function loginAsRegisteredUser(\ApiTester $I)
{
$I->wantTo('Login as registered user');
$I->sendPOST('/action.php?ap=V4&p=Customer&c=Customer&a=login',['customer' => ['email' => $this->registered_user_email, 'password' => $this->registered_user_password]]);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseMatchesJsonType(["customer" => ["id_customer"=> 'string|null',"first_name"=>'string|null',"last_name"=>'string|null',"newsletter"=>'string|null']]);
}
和id_customer字段总是比较失败
1) LoginCest: Login as registered user
Test tests/api/LoginCest.php:loginAsRegisteredUser
Step See response matches json type {"customer":{"id_customer":"string|null","first_name":"string|null","last_name":"string|null","newsletter":"string|null"}}
Fail `id_customer: 1` is of type `string|null`
响应示例:
{"customer":{"id_customer":1,"first_name":"as","last_name":"ewq","newsletter":"1"} }
我已经为字段 id_customer(例如数字)尝试了所有可能的类型,但没有一种有效。现在有人解决吗?
它实际上验证正确 - 你的期望是错误的。
预期类型为字符串或 null,但实际类型为 integer
.
我有 API 测试
public function loginAsRegisteredUser(\ApiTester $I)
{
$I->wantTo('Login as registered user');
$I->sendPOST('/action.php?ap=V4&p=Customer&c=Customer&a=login',['customer' => ['email' => $this->registered_user_email, 'password' => $this->registered_user_password]]);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseMatchesJsonType(["customer" => ["id_customer"=> 'string|null',"first_name"=>'string|null',"last_name"=>'string|null',"newsletter"=>'string|null']]);
}
和id_customer字段总是比较失败
1) LoginCest: Login as registered user
Test tests/api/LoginCest.php:loginAsRegisteredUser
Step See response matches json type {"customer":{"id_customer":"string|null","first_name":"string|null","last_name":"string|null","newsletter":"string|null"}}
Fail `id_customer: 1` is of type `string|null`
响应示例: {"customer":{"id_customer":1,"first_name":"as","last_name":"ewq","newsletter":"1"} }
我已经为字段 id_customer(例如数字)尝试了所有可能的类型,但没有一种有效。现在有人解决吗?
它实际上验证正确 - 你的期望是错误的。
预期类型为字符串或 null,但实际类型为 integer
.