testUpdateTopic () 中使用 clean () 遇到问题没搞明白?
public function testUpdateTopic()
{
$topic = $this->makeTopic();
$editData = ['category_id' => 2, 'body' => 'edit body', 'title' => 'edit title'];
$response = $this->JWTActingAs($this->user)
->json('PATCH', '/api/topics/'.$topic->id, $editData);
$assertData= [
'category_id' => 2,
'user_id' => $this->user->id,
'title' => 'edit title',
'body' => 'edit body',
];
$response->assertStatus(200)
->assertJsonFragment($assertData);
}
$assertData的'body‘键值去掉clean()函数,测试结果与教程一致。如果是:
'body' => clean('edit body' ,'user_topic_body'),
测试结果报错,'body'断言失误:
There was 1 failure:
1) Tests\Feature\TopicApiTest::testUpdateTopic
Unable to find JSON fragment:
["body":"
edit body<\/p>"]
within
[{"body":"edit body","category_id":2,"created_at":"2018-12-02 07:12:56","excerpt":"Quos facere dolore odit nihil. Quas reprehenderit non pariatur ea. Quisquam in eius ea pariatur dignissimos. Eligendi sunt dolore id eligendi incidunt.","id":140,"last_reply_user_id":0,"reply_count":0,"slug":"doloremque-autem-neque-distinctio-magni-quia-quis","title":"edit title","updated_at":"2018-12-22 21:51:04","user_id":61,"view_count":0}].
Failed asserting that false is true.
推荐文章: