如何捕获验证消息?

时间:2019-09-14 08:57:53

标签: php laravel graphql laravel-lighthouse

我对现场验证进行了一些测试。 如何断言响应错误消息? 这是我的简单测试

/** @test */
public function categoryRequiresName()
{



$response = $this->postGraphQL([
    'query' => '
        mutation CreateCategory($name: String!) {
            createCategory(name: $name) {
                name
            }
        }
    ',
    'variables' => [
        'name' => '',
    ],
]);

// how to assert Response message ?
// edited solution
$this->assertEquals("The name field is required.", $response->json("errors.0.extensions.validation.name.0"));
}

这是我在突变领域的规则

name: String @rules(apply: ["required"])

这是错误树

enter image description here

0 个答案:

没有答案