public function test_deleting_section_soft_deletes_its_subsections() { // given we have a user with a section and that sub section $user = factory(User::class, 1)->create(); // AND we have a section $section = factory(Section::class, 1)->create(['parent_id' => null, 'user_id' => $user->id]); // with subsections factory(Section::class, 6)->create(['parent_id' => $section->id, 'user_id' => $user->id]); $subsectionCount = Section::where('parent_id', $section->id)->count(); // when we delete that section $section->delete(); // then section and subsections are soft deleted $this->assertTrue($section->trashed()); // we have no subsections $this->assertEquals(Section::where('parent_id', $section->id)->count(), 0); // we have the right amount of soft deleted subsections $this->assertEquals(Section::withTrashed()->where('parent_id', $section->id)->count(), $subsectionCount); }