コード例 #1
0
 public function testComplexCountCache()
 {
     $post = new Post();
     $post->userId = $this->data['user']->id;
     $post->save();
     $comment = new Comment();
     $comment->userId = $this->data['user']->id;
     $comment->postId = $this->data['post']->id;
     $comment->save();
     $this->assertEquals(1, User::first()->commentCount);
     $this->assertEquals(1, Post::first()->commentCount);
     $comment->postId = $post->id;
     $comment->save();
     $this->assertEquals(0, Post::first()->commentCount);
     $this->assertEquals(1, Post::get()[1]->commentCount);
 }