Skip to content

Commit

Permalink
Add some tests for mutual friends feature
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-monnot committed Aug 18, 2016
1 parent de5f5c9 commit 8a5c094
Showing 1 changed file with 89 additions and 3 deletions.
92 changes: 89 additions & 3 deletions tests/FriendshipsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,92 @@ public function it_returns_user_friends_of_friends()

$this->containsOnlyInstancesOf(\App\User::class, $sender->getFriendsOfFriends());
}


}

/** @test */
public function it_returns_user_mutual_friends()
{
$sender = createUser();
$recipients = createUser([], 2);
$fofs = createUser([], 5)->chunk(3);

foreach ($recipients as $recipient) {
$sender->befriend($recipient);
$recipient->acceptFriendRequest($sender);

//add some friends to each recipient too
foreach ($fofs->shift() as $fof) {
$recipient->befriend($fof);
$fof->acceptFriendRequest($recipient);
$fof->befriend($sender);
$sender->acceptFriendRequest($fof);
}
}

$this->assertCount(3, $sender->getMutualFriends($recipients[0]));
$this->assertCount(3, $recipients[0]->getMutualFriends($sender));

$this->assertCount(2, $sender->getMutualFriends($recipients[1]));
$this->assertCount(2, $recipients[1]->getMutualFriends($sender));

$this->containsOnlyInstancesOf(\App\User::class, $sender->getMutualFriends($recipients[0]));
}

/** @test */
public function it_returns_user_mutual_friends_per_page()
{
$sender = createUser();
$recipients = createUser([], 2);
$fofs = createUser([], 8)->chunk(5);

foreach ($recipients as $recipient) {
$sender->befriend($recipient);
$recipient->acceptFriendRequest($sender);

//add some friends to each recipient too
foreach ($fofs->shift() as $fof) {
$recipient->befriend($fof);
$fof->acceptFriendRequest($recipient);
$fof->befriend($sender);
$sender->acceptFriendRequest($fof);
}
}

$this->assertCount(2, $sender->getMutualFriends($recipients[0], 2));
$this->assertCount(5, $sender->getMutualFriends($recipients[0], 0));
$this->assertCount(5, $sender->getMutualFriends($recipients[0], 10));
$this->assertCount(2, $recipients[0]->getMutualFriends($sender, 2));
$this->assertCount(5, $recipients[0]->getMutualFriends($sender, 0));
$this->assertCount(5, $recipients[0]->getMutualFriends($sender, 10));

$this->assertCount(1, $recipients[1]->getMutualFriends($recipients[0], 10));

$this->containsOnlyInstancesOf(\App\User::class, $sender->getMutualFriends($recipients[0], 2));
}

/** @test */
public function it_returns_user_mutual_friends_number()
{
$sender = createUser();
$recipients = createUser([], 2);
$fofs = createUser([], 5)->chunk(3);

foreach ($recipients as $recipient) {
$sender->befriend($recipient);
$recipient->acceptFriendRequest($sender);

//add some friends to each recipient too
foreach ($fofs->shift() as $fof) {
$recipient->befriend($fof);
$fof->acceptFriendRequest($recipient);
$fof->befriend($sender);
$sender->acceptFriendRequest($fof);
}
}

$this->assertEquals(3, $sender->getMutualFriendsCount($recipients[0]));
$this->assertEquals(3, $recipients[0]->getMutualFriendsCount($sender));

$this->assertEquals(2, $sender->getMutualFriendsCount($recipients[1]));
$this->assertEquals(2, $recipients[1]->getMutualFriendsCount($sender));
}
}

0 comments on commit 8a5c094

Please sign in to comment.