Skip to content

Commit

Permalink
WIP: Add fakesincoming and outgoing scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-monnot committed Aug 10, 2016
1 parent 2f73bd2 commit f0ecc0f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Models/Friendship.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @method \Illuminate\Database\Eloquent\Builder|Friendship accepted() Get accepted friendships
* @method \Illuminate\Database\Eloquent\Builder|Friendship blocked() Get blocked friendships
* @method \Illuminate\Database\Eloquent\Builder|Friendship denied() Get denied friendships
* @method \Illuminate\Database\Eloquent\Builder|Friendship incoming() Get incoming friendships
* @method \Illuminate\Database\Eloquent\Builder|Friendship outgoing() Get outgoing friendships
*/
class Friendship extends Model
{
Expand Down Expand Up @@ -112,6 +114,32 @@ public function scopeDenied($query)
return $query->whereStatus(Status::DENIED);
}

/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder|Friendship
*/
public function scopeIncoming($query)
{
return $query;

// @todo Need User object
$user = null;
return $query->whereRecipient($user);
}

/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder|Friendship
*/
public function scopeOutgoing($query)
{
return $query;

// @todo Need User object
$user = null;
return $query->whereSender($user);
}

/**
* @param $query
* @param Model $sender
Expand Down
24 changes: 24 additions & 0 deletions tests/FriendshipsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,28 @@ public function it_returns_blocked_requests(){
$recipients[2]->blockFriend($sender);
$this->assertCount(1, $sender->requests()->blocked()->get());
}

/** @test */
public function it_returns_incoming_requests(){
$sender = createUser();
$recipients = createUser([], 7);

$sender->befriend($recipients[0]);
$sender->befriend($recipients[1]);
$sender->befriend($recipients[2]);
$sender->befriend($recipients[3]);

$recipients[0]->acceptFriendRequest($sender);
$recipients[1]->acceptFriendRequest($sender);
$recipients[2]->denyFriendRequest($sender);
$recipients[3]->befriend($sender); // /!\ Sender firstly request to be friend
$recipients[5]->befriend($sender); // sender: 1
$recipients[6]->befriend($sender); // sender: 2
$sender->acceptFriendRequest($recipients[6]);


$this->assertCount(2, $sender->requests()->incoming()->get());
$this->assertCount(1, $recipients[3]->requests()->incoming()->get());
$this->assertCount(0, $recipients[0]->requests()->incoming()->get());
}
}

0 comments on commit f0ecc0f

Please sign in to comment.