关于 43 节的遗漏?
SubscribeToThreadsTest
中的两个测试文中交代的有些模糊,跟到最后测试无法全部通过,参照源码修改如下后与教程效果同步
/** @test */
public function a_user_can_subscribe_to_threads()
{
$this->signIn();
// Given we have a thread...
$thread = create('App\Thread');
// And the user subscribes to the thread...
$this->post($thread->path() . '/subscriptions');
$this->assertCount(1, $thread->fresh()->subscriptions);
}
/** @test */
public function a_user_can_unsubscribe_from_threads()
{
$this->signIn();
$thread = create('App\Thread');
// 这里原文笔记中忘记了一行,虽然测试不会报错,但是却不符合业务逻辑,源码中是有下面这一行,逻辑更加合理
$thread->subscribe();
$this->delete($thread->path() . '/subscriptions');
$this->assertCount(0, $thread->subscriptions);
}
推荐文章: