Skip to content

Commit

Permalink
add more comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Oct 15, 2023
1 parent fa4a2dc commit bed6650
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/Database/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function testDeleteWithThroughRelations()

$website->delete();

// verify nothing has been deleted
$this->assertEquals($phoneRelationCount, $user->phone()->count());
$this->assertEquals($postsRelationCount, $user->posts()->count());

Expand All @@ -161,14 +162,15 @@ public function testDeleteWithHasManyRelation()
$website = $this->seeded['websites'][0];
$user = $this->seeded['users'][0];

$usersRelationCount = $website->users()->count();
$websiteCount = Website::count();
$userCount = User::count();

$website->delete();

$this->assertEquals($usersRelationCount, $website->users()->count());
// verify website has been deleted
$this->assertEquals($websiteCount - 1, Website::count());

// verify user still exists
$this->assertEquals($userCount, User::count());

// test with relation "delete" flag set to true
Expand All @@ -183,7 +185,10 @@ public function testDeleteWithHasManyRelation()

$website->delete();

// verify website has been deleted
$this->assertEquals($websiteCount - 1, Website::count());

// verify user has been deleted
$this->assertEquals($userCount - 1, User::count());
}

Expand All @@ -192,13 +197,15 @@ public function testDeleteWithMorphManyRelation()
{
$post = $this->seeded['posts'][0];

$commentsRelationCount = $post->comments()->count();
$postCount = Post::count();
$commentCount = Comment::count();

$post->delete();

// verify post has been deleted
$this->assertEquals($postCount - 1, Post::count());

// verify comment still exists
$this->assertEquals($commentCount, Comment::count());

// test with relation "delete" flag set to true
Expand All @@ -213,7 +220,10 @@ public function testDeleteWithMorphManyRelation()

$post->delete();

// verify post has been deleted
$this->assertEquals($postCount - 1, Post::count());

// verify comment has been deleted
$this->assertEquals($commentCount - 1, Comment::count());
}

Expand All @@ -228,12 +238,12 @@ public function testDeleteWithBelongsToManyRelation()

$user->delete();

// verify that pivot record has been removed
$this->assertEquals($userRolePivotCount - 1, DB::table('role_user')->count());

// verify user has been deleted
$this->assertEquals($userCount - 1, User::count());

// verify that pivot record has been removed
$this->assertEquals($userRolePivotCount - 1, DB::table('role_user')->count());

// verify both roles still exist
$this->assertEquals($roleCount, Role::count());

Expand Down

0 comments on commit bed6650

Please sign in to comment.