如何在seeJsonStructure Laravel Unit测试中断言值

时间:2017-01-21 02:08:48

标签: php laravel unit-testing phpunit

我想测试我的字段名称...有人可以解释我如何做这样的事情:

'field'=> '电子邮件'......等等。

我的方法测试

public function testAuthWithoutValidEmail()
{
    $this->json('POST', "{$this->baseUrl}/{$this->version}/auth/company",
        ['email' => 'xpto@xpto', 'password' => '123456'],
        ['Content-Type' => 'application/json'])
        ->seeJsonStructure([
            'requestTime',
            'data' => [
                '*' => [
                    'field',
                    'rule',
                    'composed_rule',
                    'message',
                    'tag'
                ]
            ],
        ])->seeJson([
            'user'  => null,
            'token' => null
        ])->assertResponseStatus(\App\Http\Middleware\Constants\HttpStatusCodes::BAD_REQUEST);
}

我的结果json数据:

{  "requestTime": 522,
      "data": [
        {
          "field": "email",
          "rule": "Email",
          "composed_rule": "Email",
          "message": "The email must be a valid email address.",
          "tag": "ERROR_FORM_EMAIL_EMAIL"
        }
      ],
      "user": null,
      "token": null
    }

0 个答案:

没有答案