[已解决] test_authorized_users_can_delete_threads 通不过 :joy:

原因:

ThreadPolicy::update 里写成全等了,改为 == 就好了
PhpStorm 里取出来的数据,Thread::user_id => 1 是数字
但在 命令行Thread::user_id => '1' 里是 '1' 字符串
好坑啊 :joy:

    public function update(User $user, Thread $thread)
    {
        return $user->id === $thread->user_id;
    }

问题

PhpStorm 里跑 test_authorized_users_can_delete_threads 能过

CreateThreadsTest

use DatabaseMigrations;

public function test_authorized_users_can_delete_threads()
{
    $this->signIn();

    $thread = create('App\Thread', ['user_id' => auth()->id()]);
    $reply = create('App\Reply', ['thread_id' => $thread->id]);

    $response = $this->json('DELETE', $thread->path());

    $response->assertStatus(204);

    $this->assertDatabaseMissing($thread->getTable(), ['id' => $thread->id]);
    $this->assertDatabaseMissing($reply->getTable(), ['id' => $reply->id]);
}

在命令行里跑,就是报错 :joy:
file

Luff
Luff
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

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