示例#1
0
 /** @test */
 public function it_deletes_all_specified_relations()
 {
     $user = User::create([]);
     $author = Author::create(['user_id' => $user->id]);
     $post = Post::create(['author_id' => $author->id]);
     $comment = Comment::create(['post_id' => $post->id]);
     $user = $user->fresh();
     $this->assertEquals($user->author()->count(), 1, 'author');
     $this->assertEquals($user->author()->first()->posts()->count(), 1, 'posts');
     $this->assertEquals($user->author()->first()->posts()->first()->comments()->count(), 1, 'comments');
     $user->delete();
     $this->assertEquals(Post::where('author_id', 1)->count(), 0, 'post 0');
     $this->assertEquals(Comment::where('post_id', 1)->count(), 0, 'comment 0');
     $this->assertEquals(Author::where('user_id', 1)->count(), 0, 'user 0');
 }