PHPUnit 在断言它在视图中看到一个值时给了我一个错误

当我运行具有 2 个断言 ( assertSee)的功能测试时,PHPUnit 仅识别一个 ( title) 而不是description,即使我可以清楚地看到它dd()是从控制器传递到视图的值。


考试:


/** @test */

    public function a_user_can_view_a_project(){

        $this->withoutExceptionHandling();

        $project = factory('App\Project')->create();

        $this->get('/projects/'.$project->id)->assertSee('title')->assertSee('description');

    }

错误:


Failed asserting that '<!doctype html>\n

<html>\n

<head>\n

    <meta charset="UTF-8">\n

    <meta name="viewport"\n

          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">\n

    <meta http-equiv="X-UA-Compatible" content="ie=edge">\n

    <title>Document</title>\n

</head>\n

<body>\n

    <h3>Fugit molestias explicabo odio quis.</h3>\n

    <p>Quis aut consectetur quisquam a dolores voluptatibus. Quas quos quo iusto beatae sint voluptatem aspernatur. Molestiae repudiandae suscipit non vel. Ea quasi et eveniet.</p>\n

    Quis aut consectetur quisquam a dolores voluptatibus. Quas quos quo iusto beatae sint voluptatem aspernatur. Molestiae repudiandae suscipit non vel. Ea quasi et eveniet.\n

</body>\n

</html>\n

' contains "description".

该段落是它无法“看到”的描述。


dd():


.

.

.

#attributes: array:5 [▼

    "id" => 1

    "title" => "First Project"

    "description" => "asdsdasdsadsadsadsadsa"

    "created_at" => null

    "updated_at" => null

  ]

.

.

.


慕尼黑8549860
浏览 212回答 1
1回答

斯蒂芬大帝

要测试某个变量是否已传递给您的响应(在您的案例中为视图),您需要使用$response->assertViewHas("project",$project);该assertSee()方法只检查作为参数传递的字符串是否是纯文本响应的子字符串。
打开App,查看更多内容
随时随地看视频慕课网APP