Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add deprecate notes #40

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"laravel/laravel": "5.*",
"codeclimate/php-test-reporter": "^0.3.2",
"mockery/mockery": "^0.9.5",
"doctrine/dbal": "^2.5"
"doctrine/dbal": "^2.5",
"symfony/phpunit-bridge": "^3.1"
},
"autoload": {
"psr-4": {
Expand Down
48 changes: 42 additions & 6 deletions src/Traits/Friendable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function befriend(Model $recipient)
'status' => Status::PENDING,
]);

$this->friends()->save($friendship);
$this->friendshipRequests()->save($friendship);

Event::fire('friendships.sent', [$this, $recipient]);

Expand Down Expand Up @@ -185,7 +185,7 @@ public function blockFriend(Model $recipient)

Event::fire('friendships.blocked', [$this, $recipient]);

return $this->friends()->save($friendship);
return $this->friendshipRequests()->save($friendship);
}

/**
Expand All @@ -201,63 +201,81 @@ public function unblockFriend(Model $recipient)
}

/**
* @deprecated Will be removed in version 2
*
* @param Model $recipient
*
* @return \Hootlex\Friendships\Models\Friendship
*/
public function getFriendship(Model $recipient)
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->findFriendship($recipient)->first();
}

/**
* @deprecated Will be removed in version 2
*
* @return \Illuminate\Database\Eloquent\Collection
*
* @param string $groupSlug
*
*/
public function getAllFriendships($groupSlug = '')
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->findFriendships(null, $groupSlug)->get();
}

/**
* @deprecated Will be removed in version 2
*
* @return \Illuminate\Database\Eloquent\Collection
*
* @param string $groupSlug
*
*/
public function getPendingFriendships($groupSlug = '')
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->findFriendships(Status::PENDING, $groupSlug)->get();
}

/**
* @deprecated Will be removed in version 2
*
* @return \Illuminate\Database\Eloquent\Collection
*
* @param string $groupSlug
*
*/
public function getAcceptedFriendships($groupSlug = '')
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->findFriendships(Status::ACCEPTED, $groupSlug)->get();
}

/**
* @deprecated Will be removed in version 2
*
* @return \Illuminate\Database\Eloquent\Collection
*
*/
public function getDeniedFriendships()
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->findFriendships(Status::DENIED)->get();
}

/**
* @deprecated Will be removed in version 2
*
* @return \Illuminate\Database\Eloquent\Collection
*
*/
public function getBlockedFriendships()
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->findFriendships(Status::BLOCKED)->get();
}

Expand All @@ -268,7 +286,7 @@ public function getBlockedFriendships()
*/
public function hasBlocked(Model $recipient)
{
return $this->friends()->whereRecipient($recipient)->whereStatus(Status::BLOCKED)->exists();
return $this->friendshipRequests()->whereRecipient($recipient)->whereStatus(Status::BLOCKED)->exists();
}

/**
Expand All @@ -282,27 +300,33 @@ public function isBlockedBy(Model $recipient)
}

/**
* @deprecated Will be removed in version 2.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getFriendRequests()
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0.'), E_USER_DEPRECATED);
return Friendship::whereRecipient($this)->whereStatus(Status::PENDING)->get();
}

/**
* This method will not return Friendship models
* It will return the 'friends' models. ex: App\User
*
* @deprecated Will be removed in version 2
*
* @param int $perPage Number
* @param string $groupSlug
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function getFriends($perPage = 0, $groupSlug = '')
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->getOrPaginate($this->getFriendsQueryBuilder($groupSlug), $perPage);
}

/**
* This method will not return Friendship models
* It will return the 'friends' models. ex: App\User
Expand All @@ -315,7 +339,7 @@ public function getMutualFriends(Model $other, $perPage = 0)
{
return $this->getOrPaginate($this->getMutualFriendsQueryBuilder($other), $perPage);
}

/**
* Get the number of friends
*
Expand All @@ -337,6 +361,7 @@ public function getMutualFriendsCount($other)
public function getFriendsOfFriends($perPage = 0)
{
return $this->getOrPaginate($this->friendsOfFriendsQueryBuilder(), $perPage);

}


Expand Down Expand Up @@ -368,7 +393,7 @@ public function canBefriend($recipient)
}

// if sender has a friendship with the recipient return false
if ($friendship = $this->getFriendship($recipient)) {
if ($friendship = $this->findFriendship($recipient)->first()) {
// if previous friendship was Denied then let the user send fr
if ($friendship->status != Status::DENIED) {
return false;
Expand Down Expand Up @@ -497,9 +522,20 @@ private function friendsOfFriendsQueryBuilder($groupSlug = '')
}

/**
* @deprecated Will be removed in version 2
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function friends()
{
@trigger_error(sprintf('The ' . __METHOD__ . ' method was deprecated in version 1.1 and will be removed in version 2.0. You should implement this method yourself in %s.', get_class($this)), E_USER_DEPRECATED);
return $this->morphMany(Friendship::class, 'sender');
}

/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
protected function friendshipRequests()
{
return $this->morphMany(Friendship::class, 'sender');
}
Expand Down
5 changes: 4 additions & 1 deletion tests/FriendshipsEventsTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

require_once 'Test.php';

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Test as BaseTest;

class FriendshipsEventsTest extends TestCase
class FriendshipsEventsTest extends BaseTest
{
// use DatabaseTransactions;

Expand Down
13 changes: 8 additions & 5 deletions tests/FriendshipsGroupsTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php

require_once 'Test.php';

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Test as BaseTest;

/*
/**
* Test User Personal Friend Groups
*/
class FriendshipsGroupsTest extends TestCase
* @group legacy
*/
class FriendshipsGroupsTest extends BaseTest
{
use DatabaseTransactions;



/** @test */
public function user_can_add_a_friend_to_a_group()
{
Expand Down
13 changes: 10 additions & 3 deletions tests/FriendshipsTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php

require_once 'Test.php';

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Test as BaseTest;

class FriendshipsTest extends TestCase
/**
* Test User Friend
* @group legacy
*/
class FriendshipsTest extends BaseTest
{
// use DatabaseTransactions;
use DatabaseTransactions;

/** @test */
public function user_can_send_a_friend_request()
{
Expand Down
26 changes: 26 additions & 0 deletions tests/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

abstract class Test extends TestCase
{
public function createApplication()
{
$app = require __DIR__ . '/../vendor/laravel/laravel/bootstrap/app.php';

if ( ! $app->hasBeenBootstrapped())
{
$app->bootstrapWith(
[
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\ConfigureLogging',
'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\SetRequestForConsole',
'Illuminate\Foundation\Bootstrap\RegisterProviders',
'Illuminate\Foundation\Bootstrap\BootProviders',
]
);
}

return $app;
}
}