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.

not only a learner , but also a user .
ruodee
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
liyu001989
最佳答案

你的 body 的处理是自己修改了吗,github 上下载项目对比一下吧,你数据库中的数据为什么没有增加 p 标签

5年前 评论
讨论数量: 2
liyu001989

你的 body 的处理是自己修改了吗,github 上下载项目对比一下吧,你数据库中的数据为什么没有增加 p 标签

5年前 评论
ruodee

果然,TopicObserver观察器中的creating()方法有问题,感谢@liyu001989

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!