当我运行具有 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 ]...
1 回答
斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
要测试某个变量是否已传递给您的响应(在您的案例中为视图),您需要使用
$response->assertViewHas("project",$project);
该assertSee()
方法只检查作为参数传递的字符串是否是纯文本响应的子字符串。
- 1 回答
- 0 关注
- 211 浏览
添加回答
举报
0/150
提交
取消