[已解决] 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 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

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