From 1fa7f7d4bc5d727d6696080d17b2eb39e34ae237 Mon Sep 17 00:00:00 2001 From: mfn Date: Wed, 21 Feb 2024 08:13:25 +0000 Subject: [PATCH] style: php-cs-fixer --- src/Blacklist.php | 2 - src/Claims/Audience.php | 3 - src/Claims/Claim.php | 18 +---- src/Claims/Collection.php | 12 +--- src/Claims/Custom.php | 1 - src/Claims/DatetimeTrait.php | 17 +---- src/Claims/Expiration.php | 6 -- src/Claims/Factory.php | 1 - src/Claims/IssuedAt.php | 12 ---- src/Claims/Issuer.php | 3 - src/Claims/JwtId.php | 3 - src/Claims/NotBefore.php | 5 -- src/Claims/Subject.php | 3 - src/Console/EnvHelperTrait.php | 3 +- src/Contracts/Claim.php | 8 +-- src/Contracts/JWTSubject.php | 2 - src/Contracts/Providers/Auth.php | 8 --- src/Contracts/Providers/Storage.php | 4 -- src/Contracts/Validator.php | 2 - src/Exceptions/InvalidClaimException.php | 3 +- src/Exceptions/JWTException.php | 7 +- src/Factory.php | 1 - src/Http/Middleware/Authenticate.php | 5 +- src/Http/Middleware/AuthenticateAndRenew.php | 5 +- src/Http/Middleware/Check.php | 8 +-- src/Http/Middleware/RefreshToken.php | 5 +- src/JWT.php | 9 +-- src/JWTGuard.php | 32 ++++----- src/Manager.php | 10 +-- src/Payload.php | 29 +-------- src/Providers/Auth/Illuminate.php | 4 -- src/Providers/JWT/Lcobucci.php | 21 ++---- src/Providers/JWT/Namshi.php | 15 ++--- src/Providers/LaravelServiceProvider.php | 6 -- src/Providers/LumenServiceProvider.php | 3 - src/Providers/Storage/Illuminate.php | 11 +--- src/Validators/PayloadValidator.php | 4 +- tests/AbstractTestCase.php | 3 +- tests/BlacklistTest.php | 8 +-- tests/Claims/DatetimeClaimTest.php | 27 ++++---- tests/FactoryTest.php | 5 +- tests/Fixtures/Foo.php | 3 - tests/Http/ParserTest.php | 14 ++-- tests/JWTAuthTest.php | 42 ++++++------ tests/JWTGuardTest.php | 65 +++++++++---------- tests/ManagerTest.php | 9 ++- tests/Middleware/AbstractMiddlewareTest.php | 5 +- tests/Middleware/AuthenticateAndRenewTest.php | 7 +- tests/Middleware/AuthenticateTest.php | 9 ++- tests/Middleware/CheckTest.php | 7 +- tests/Middleware/RefreshTokenTest.php | 7 +- tests/PayloadTest.php | 6 +- tests/Providers/Auth/IlluminateTest.php | 3 +- tests/Providers/JWT/LcobucciTest.php | 31 ++++----- tests/Providers/JWT/NamshiTest.php | 33 +++++----- tests/Providers/Storage/IlluminateTest.php | 5 +- tests/Stubs/JWTProviderStub.php | 3 - tests/Validators/TokenValidatorTest.php | 4 ++ 58 files changed, 186 insertions(+), 401 deletions(-) diff --git a/src/Blacklist.php b/src/Blacklist.php index d79d652f..07e79ef9 100644 --- a/src/Blacklist.php +++ b/src/Blacklist.php @@ -187,8 +187,6 @@ public function getGracePeriod() /** * Get the unique key held within the blacklist. - * - * @return mixed */ public function getKey(Payload $payload) { diff --git a/src/Claims/Audience.php b/src/Claims/Audience.php index 40ab3d51..9585f7ef 100644 --- a/src/Claims/Audience.php +++ b/src/Claims/Audience.php @@ -14,8 +14,5 @@ class Audience extends Claim { - /** - * {@inheritdoc} - */ protected $name = 'aud'; } diff --git a/src/Claims/Claim.php b/src/Claims/Claim.php index c5609e17..2322a2ef 100644 --- a/src/Claims/Claim.php +++ b/src/Claims/Claim.php @@ -14,11 +14,10 @@ use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; -use JsonSerializable; use PHPOpenSourceSaver\JWTAuth\Contracts\Claim as ClaimContract; use PHPOpenSourceSaver\JWTAuth\Exceptions\InvalidClaimException; -abstract class Claim implements Arrayable, ClaimContract, Jsonable, JsonSerializable +abstract class Claim implements Arrayable, ClaimContract, Jsonable, \JsonSerializable { /** * The claim name. @@ -29,14 +28,10 @@ abstract class Claim implements Arrayable, ClaimContract, Jsonable, JsonSerializ /** * The claim value. - * - * @var mixed */ private $value; /** - * @param mixed $value - * * @return void * * @throws InvalidClaimException @@ -49,11 +44,9 @@ public function __construct($value) /** * Set the claim value, and call a validate method. * - * @param mixed $value + * @return $this * * @throws InvalidClaimException - * - * @return $this */ public function setValue($value) { @@ -64,8 +57,6 @@ public function setValue($value) /** * Get the claim value. - * - * @return mixed */ public function getValue() { @@ -99,8 +90,6 @@ public function getName() /** * Validate the claim in a standalone Claim context. * - * @param mixed $value - * * @return bool */ public function validateCreate($value) @@ -133,8 +122,7 @@ public function validateRefresh($refreshTTL) /** * Checks if the value matches the claim. * - * @param mixed $value - * @param bool $strict + * @param bool $strict * * @return bool */ diff --git a/src/Claims/Collection.php b/src/Claims/Collection.php index 9174834d..2553556c 100644 --- a/src/Claims/Collection.php +++ b/src/Claims/Collection.php @@ -20,8 +20,6 @@ class Collection extends IlluminateCollection /** * Create a new collection. * - * @param mixed $items - * * @return void */ public function __construct($items = []) @@ -33,11 +31,10 @@ public function __construct($items = []) * Get a Claim instance by it's unique name. * * @param string $name - * @param mixed $default * * @return Claim */ - public function getByClaimName($name, callable $callback = null, $default = null) + public function getByClaimName($name, ?callable $callback = null, $default = null) { return $this->filter(function (Claim $claim) use ($name) { return $claim->getName() === $name; @@ -69,8 +66,6 @@ public function validate($context = 'payload') /** * Determine if the Collection contains all of the given keys. * - * @param mixed $claims - * * @return bool */ public function hasAllClaims($claims) @@ -90,9 +85,6 @@ public function toPlainArray() })->toArray(); } - /** - * {@inheritdoc} - */ protected function getArrayableItems($items) { return $this->sanitizeClaims($items); @@ -101,8 +93,6 @@ protected function getArrayableItems($items) /** * Ensure that the given claims array is keyed by the claim name. * - * @param mixed $items - * * @return array */ private function sanitizeClaims($items) diff --git a/src/Claims/Custom.php b/src/Claims/Custom.php index 1d0d57a3..242765b0 100644 --- a/src/Claims/Custom.php +++ b/src/Claims/Custom.php @@ -18,7 +18,6 @@ class Custom extends Claim { /** * @param string $name - * @param mixed $value * * @return void * diff --git a/src/Claims/DatetimeTrait.php b/src/Claims/DatetimeTrait.php index edbbebc5..d6a87625 100644 --- a/src/Claims/DatetimeTrait.php +++ b/src/Claims/DatetimeTrait.php @@ -12,8 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Claims; -use DateInterval; -use DateTimeInterface; use PHPOpenSourceSaver\JWTAuth\Exceptions\InvalidClaimException; use PHPOpenSourceSaver\JWTAuth\Support\Utils; @@ -29,28 +27,23 @@ trait DatetimeTrait /** * Set the claim value, and call a validate method. * - * @param mixed $value + * @return $this * * @throws InvalidClaimException - * - * @return $this */ public function setValue($value) { - if ($value instanceof DateInterval) { + if ($value instanceof \DateInterval) { $value = Utils::now()->add($value); } - if ($value instanceof DateTimeInterface) { + if ($value instanceof \DateTimeInterface) { $value = $value->getTimestamp(); } return parent::setValue($value); } - /** - * {@inheritdoc} - */ public function validateCreate($value) { if (!is_numeric($value)) { @@ -63,8 +56,6 @@ public function validateCreate($value) /** * Determine whether the value is in the future. * - * @param mixed $value - * * @return bool */ protected function isFuture($value) @@ -75,8 +66,6 @@ protected function isFuture($value) /** * Determine whether the value is in the past. * - * @param mixed $value - * * @return bool */ protected function isPast($value) diff --git a/src/Claims/Expiration.php b/src/Claims/Expiration.php index 35769482..1f3d426b 100644 --- a/src/Claims/Expiration.php +++ b/src/Claims/Expiration.php @@ -18,14 +18,8 @@ class Expiration extends Claim { use DatetimeTrait; - /** - * {@inheritdoc} - */ protected $name = 'exp'; - /** - * {@inheritdoc} - */ public function validatePayload() { if ($this->isPast($this->getValue())) { diff --git a/src/Claims/Factory.php b/src/Claims/Factory.php index 6a6ecd87..93cb498a 100644 --- a/src/Claims/Factory.php +++ b/src/Claims/Factory.php @@ -69,7 +69,6 @@ public function __construct(Request $request) * Get the instance of the claim when passing the name and value. * * @param string $name - * @param mixed $value * * @return Claim * diff --git a/src/Claims/IssuedAt.php b/src/Claims/IssuedAt.php index e306ee06..005025a1 100644 --- a/src/Claims/IssuedAt.php +++ b/src/Claims/IssuedAt.php @@ -22,14 +22,8 @@ class IssuedAt extends Claim validateCreate as commonValidateCreate; } - /** - * {@inheritdoc} - */ protected $name = 'iat'; - /** - * {@inheritdoc} - */ public function validateCreate($value) { $this->commonValidateCreate($value); @@ -41,9 +35,6 @@ public function validateCreate($value) return $value; } - /** - * {@inheritdoc} - */ public function validatePayload() { if ($this->isFuture($this->getValue())) { @@ -51,9 +42,6 @@ public function validatePayload() } } - /** - * {@inheritdoc} - */ public function validateRefresh($refreshTTL) { if ($this->isPast($this->getValue() + $refreshTTL * 60)) { diff --git a/src/Claims/Issuer.php b/src/Claims/Issuer.php index 715d405e..f2c023d0 100644 --- a/src/Claims/Issuer.php +++ b/src/Claims/Issuer.php @@ -14,8 +14,5 @@ class Issuer extends Claim { - /** - * {@inheritdoc} - */ protected $name = 'iss'; } diff --git a/src/Claims/JwtId.php b/src/Claims/JwtId.php index 8d6d86dc..3bf05f11 100644 --- a/src/Claims/JwtId.php +++ b/src/Claims/JwtId.php @@ -14,8 +14,5 @@ class JwtId extends Claim { - /** - * {@inheritdoc} - */ protected $name = 'jti'; } diff --git a/src/Claims/NotBefore.php b/src/Claims/NotBefore.php index 8080623b..ee0878a2 100644 --- a/src/Claims/NotBefore.php +++ b/src/Claims/NotBefore.php @@ -18,14 +18,9 @@ class NotBefore extends Claim { use DatetimeTrait; - /** - * {@inheritdoc} - */ protected $name = 'nbf'; /** - * {@inheritdoc} - * * @throws TokenInvalidException */ public function validatePayload() diff --git a/src/Claims/Subject.php b/src/Claims/Subject.php index a9d389bc..e1cbdf87 100644 --- a/src/Claims/Subject.php +++ b/src/Claims/Subject.php @@ -14,8 +14,5 @@ class Subject extends Claim { - /** - * {@inheritdoc} - */ protected $name = 'sub'; } diff --git a/src/Console/EnvHelperTrait.php b/src/Console/EnvHelperTrait.php index 7b0ea542..405ad846 100644 --- a/src/Console/EnvHelperTrait.php +++ b/src/Console/EnvHelperTrait.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Console; -use Closure; use Illuminate\Support\Str; trait EnvHelperTrait @@ -30,7 +29,7 @@ protected function envFileExists(): bool * * @param string|int $value */ - public function updateEnvEntry(string $key, $value, Closure $confirmOnExisting = null): bool + public function updateEnvEntry(string $key, $value, ?\Closure $confirmOnExisting = null): bool { $filepath = $this->envPath(); diff --git a/src/Contracts/Claim.php b/src/Contracts/Claim.php index d9d06105..d2aba815 100644 --- a/src/Contracts/Claim.php +++ b/src/Contracts/Claim.php @@ -19,18 +19,14 @@ interface Claim /** * Set the claim value, and call a validate method. * - * @param mixed $value + * @return $this * * @throws InvalidClaimException - * - * @return $this */ public function setValue($value); /** * Get the claim value. - * - * @return mixed */ public function getValue(); @@ -53,8 +49,6 @@ public function getName(); /** * Validate the Claim value. * - * @param mixed $value - * * @return bool */ public function validateCreate($value); diff --git a/src/Contracts/JWTSubject.php b/src/Contracts/JWTSubject.php index 0142480b..205f52ab 100644 --- a/src/Contracts/JWTSubject.php +++ b/src/Contracts/JWTSubject.php @@ -16,8 +16,6 @@ interface JWTSubject { /** * Get the identifier that will be stored in the subject claim of the JWT. - * - * @return mixed */ public function getJWTIdentifier(); diff --git a/src/Contracts/Providers/Auth.php b/src/Contracts/Providers/Auth.php index 7c6b5419..4855f553 100644 --- a/src/Contracts/Providers/Auth.php +++ b/src/Contracts/Providers/Auth.php @@ -16,24 +16,16 @@ interface Auth { /** * Check a user's credentials. - * - * @return mixed */ public function byCredentials(array $credentials); /** * Authenticate a user via the id. - * - * @param mixed $id - * - * @return mixed */ public function byId($id); /** * Get the currently authenticated user. - * - * @return mixed */ public function user(); } diff --git a/src/Contracts/Providers/Storage.php b/src/Contracts/Providers/Storage.php index 6fc56f1a..6c2bf52d 100644 --- a/src/Contracts/Providers/Storage.php +++ b/src/Contracts/Providers/Storage.php @@ -16,7 +16,6 @@ interface Storage { /** * @param string $key - * @param mixed $value * @param int $minutes * * @return void @@ -25,7 +24,6 @@ public function add($key, $value, $minutes); /** * @param string $key - * @param mixed $value * * @return void */ @@ -33,8 +31,6 @@ public function forever($key, $value); /** * @param string $key - * - * @return mixed */ public function get($key); diff --git a/src/Contracts/Validator.php b/src/Contracts/Validator.php index 857d5ff0..1b00df0c 100644 --- a/src/Contracts/Validator.php +++ b/src/Contracts/Validator.php @@ -17,8 +17,6 @@ interface Validator /** * Perform some checks on the value. * - * @param mixed $value - * * @return void */ public function check($value); diff --git a/src/Exceptions/InvalidClaimException.php b/src/Exceptions/InvalidClaimException.php index 679931ec..56b5d8d8 100644 --- a/src/Exceptions/InvalidClaimException.php +++ b/src/Exceptions/InvalidClaimException.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Exceptions; -use Exception; use PHPOpenSourceSaver\JWTAuth\Claims\Claim; class InvalidClaimException extends JWTException @@ -24,7 +23,7 @@ class InvalidClaimException extends JWTException * * @return void */ - public function __construct(Claim $claim, $code = 0, Exception $previous = null) + public function __construct(Claim $claim, $code = 0, ?\Exception $previous = null) { parent::__construct('Invalid value provided for claim ['.$claim->getName().']', $code, $previous); } diff --git a/src/Exceptions/JWTException.php b/src/Exceptions/JWTException.php index 020ecdf2..6afdca4d 100644 --- a/src/Exceptions/JWTException.php +++ b/src/Exceptions/JWTException.php @@ -12,12 +12,7 @@ namespace PHPOpenSourceSaver\JWTAuth\Exceptions; -use Exception; - -class JWTException extends Exception +class JWTException extends \Exception { - /** - * {@inheritdoc} - */ protected $message = 'An error occurred'; } diff --git a/src/Factory.php b/src/Factory.php index 39a1315a..8891998b 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -116,7 +116,6 @@ protected function addClaims(array $claims) * Add a claim to the Payload. * * @param string $name - * @param mixed $value * * @return $this */ diff --git a/src/Http/Middleware/Authenticate.php b/src/Http/Middleware/Authenticate.php index 57bca086..1eced642 100644 --- a/src/Http/Middleware/Authenticate.php +++ b/src/Http/Middleware/Authenticate.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Http\Middleware; -use Closure; use Illuminate\Http\Request; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; @@ -23,11 +22,9 @@ class Authenticate extends BaseMiddleware * * @param Request $request * - * @return mixed - * * @throws UnauthorizedHttpException */ - public function handle($request, Closure $next) + public function handle($request, \Closure $next) { $this->authenticate($request); diff --git a/src/Http/Middleware/AuthenticateAndRenew.php b/src/Http/Middleware/AuthenticateAndRenew.php index 09a061a7..1229874d 100644 --- a/src/Http/Middleware/AuthenticateAndRenew.php +++ b/src/Http/Middleware/AuthenticateAndRenew.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Http\Middleware; -use Closure; use Illuminate\Http\Request; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; @@ -23,11 +22,9 @@ class AuthenticateAndRenew extends BaseMiddleware * * @param Request $request * - * @return mixed - * * @throws UnauthorizedHttpException */ - public function handle($request, Closure $next) + public function handle($request, \Closure $next) { $this->authenticate($request); diff --git a/src/Http/Middleware/Check.php b/src/Http/Middleware/Check.php index 9e8d70fa..70f66407 100644 --- a/src/Http/Middleware/Check.php +++ b/src/Http/Middleware/Check.php @@ -12,8 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Http\Middleware; -use Closure; -use Exception; use Illuminate\Http\Request; class Check extends BaseMiddleware @@ -22,15 +20,13 @@ class Check extends BaseMiddleware * Handle an incoming request. * * @param Request $request - * - * @return mixed */ - public function handle($request, Closure $next) + public function handle($request, \Closure $next) { if ($this->auth->parser()->setRequest($request)->hasToken()) { try { $this->auth->parseToken()->authenticate(); - } catch (Exception $e) { + } catch (\Exception $e) { } } diff --git a/src/Http/Middleware/RefreshToken.php b/src/Http/Middleware/RefreshToken.php index 99a4348d..aa337499 100644 --- a/src/Http/Middleware/RefreshToken.php +++ b/src/Http/Middleware/RefreshToken.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Http\Middleware; -use Closure; use Illuminate\Http\Request; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; @@ -24,11 +23,9 @@ class RefreshToken extends BaseMiddleware * * @param Request $request * - * @return mixed - * * @throws UnauthorizedHttpException */ - public function handle($request, Closure $next) + public function handle($request, \Closure $next) { $this->checkForToken($request); diff --git a/src/JWT.php b/src/JWT.php index 31cf539b..60fe15ce 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth; -use BadMethodCallException; use Illuminate\Http\Request; use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; @@ -208,8 +207,6 @@ public function payload() * Convenience method to get a claim value. * * @param string $claim - * - * @return mixed */ public function getClaim($claim) { @@ -392,9 +389,7 @@ public function blacklist() * @param string $method * @param array $parameters * - * @return mixed - * - * @throws BadMethodCallException + * @throws \BadMethodCallException */ public function __call($method, $parameters) { @@ -402,6 +397,6 @@ public function __call($method, $parameters) return call_user_func_array([$this->manager, $method], $parameters); } - throw new BadMethodCallException("Method [$method] does not exist."); + throw new \BadMethodCallException("Method [$method] does not exist."); } } diff --git a/src/JWTGuard.php b/src/JWTGuard.php index 11878a83..a1d2d90e 100644 --- a/src/JWTGuard.php +++ b/src/JWTGuard.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth; -use BadMethodCallException; use Illuminate\Auth\Events\Attempting; use Illuminate\Auth\Events\Authenticated; use Illuminate\Auth\Events\Failed; @@ -101,9 +100,9 @@ public function user() } if ( - $this->jwt->setRequest($this->request)->getToken() && - ($payload = $this->jwt->check(true)) && - $this->validateSubject() + $this->jwt->setRequest($this->request)->getToken() + && ($payload = $this->jwt->check(true)) + && $this->validateSubject() ) { return $this->user = $this->provider->retrieveById($payload['sub']); } @@ -217,8 +216,6 @@ public function invalidate($forceForever = false) /** * Create a new token by User id. * - * @param mixed $id - * * @return string|null */ public function tokenById($id) @@ -247,8 +244,6 @@ public function once(array $credentials = []) /** * Log the given User into the application. * - * @param mixed $id - * * @return bool */ public function onceUsingId($id) @@ -265,8 +260,6 @@ public function onceUsingId($id) /** * Alias for onceUsingId. * - * @param mixed $id - * * @return bool */ public function byId($id) @@ -425,7 +418,6 @@ public function getLastAttempted() /** * Determine if the user matches the credentials. * - * @param mixed $user * @param array $credentials * * @return bool @@ -462,7 +454,7 @@ protected function validateSubject() * * @return JWT * - * @throws \PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException + * @throws JWTException */ protected function requireToken() { @@ -525,7 +517,7 @@ protected function fireFailedEvent($user, array $credentials) /** * Fire the authenticated event. * - * @param \Illuminate\Contracts\Auth\Authenticatable $user + * @param Authenticatable $user * * @return void */ @@ -540,8 +532,8 @@ protected function fireAuthenticatedEvent($user) /** * Fire the login event. * - * @param \Illuminate\Contracts\Auth\Authenticatable $user - * @param bool $remember + * @param Authenticatable $user + * @param bool $remember * * @return void */ @@ -557,8 +549,8 @@ protected function fireLoginEvent($user, $remember = false) /** * Fire the logout event. * - * @param \Illuminate\Contracts\Auth\Authenticatable $user - * @param bool $remember + * @param Authenticatable $user + * @param bool $remember * * @return void */ @@ -576,9 +568,7 @@ protected function fireLogoutEvent($user, $remember = false) * @param string $method * @param array $parameters * - * @return mixed - * - * @throws BadMethodCallException + * @throws \BadMethodCallException */ public function __call($method, $parameters) { @@ -590,6 +580,6 @@ public function __call($method, $parameters) return $this->macroCall($method, $parameters); } - throw new BadMethodCallException("Method [$method] does not exist."); + throw new \BadMethodCallException("Method [$method] does not exist."); } } diff --git a/src/Manager.php b/src/Manager.php index 3e665ec8..dbfc3643 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -94,7 +94,7 @@ public function encode(Payload $payload) * * @return Payload * - * @throws \PHPOpenSourceSaver\JWTAuth\Exceptions\TokenBlacklistedException + * @throws TokenBlacklistedException */ public function decode(Token $token, $checkBlacklist = true) { @@ -106,10 +106,10 @@ public function decode(Token $token, $checkBlacklist = true) ->make(); if ( - $checkBlacklist && - $this->blacklistEnabled && - $this->getBlackListExceptionEnabled() && - $this->blacklist->has($payload) + $checkBlacklist + && $this->blacklistEnabled + && $this->getBlackListExceptionEnabled() + && $this->blacklist->has($payload) ) { throw new TokenBlacklistedException('The token has been blacklisted'); } diff --git a/src/Payload.php b/src/Payload.php index 5b0b0e61..9c7e0fb1 100644 --- a/src/Payload.php +++ b/src/Payload.php @@ -12,20 +12,16 @@ namespace PHPOpenSourceSaver\JWTAuth; -use ArrayAccess; -use BadMethodCallException; -use Countable; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Arr; use Illuminate\Support\Str; -use JsonSerializable; use PHPOpenSourceSaver\JWTAuth\Claims\Claim; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Exceptions\PayloadException; use PHPOpenSourceSaver\JWTAuth\Validators\PayloadValidator; -class Payload implements ArrayAccess, Arrayable, Countable, Jsonable, JsonSerializable +class Payload implements \ArrayAccess, Arrayable, \Countable, Jsonable, \JsonSerializable { /** * The collection of claims. @@ -92,10 +88,6 @@ public function matchesStrict(array $values) /** * Get the payload. - * - * @param mixed $claim - * - * @return mixed */ public function get($claim = null) { @@ -192,8 +184,6 @@ public function __toString() /** * Determine if an item exists at an offset. * - * @param mixed $key - * * @return bool */ #[\ReturnTypeWillChange] @@ -204,10 +194,6 @@ public function offsetExists($key) /** * Get an item at a given offset. - * - * @param mixed $key - * - * @return mixed */ #[\ReturnTypeWillChange] public function offsetGet($key) @@ -218,9 +204,6 @@ public function offsetGet($key) /** * Don't allow changing the payload as it should be immutable. * - * @param mixed $key - * @param mixed $value - * * @throws PayloadException */ #[\ReturnTypeWillChange] @@ -257,10 +240,6 @@ public function count() /** * Invoke the Payload as a callable function. - * - * @param mixed $claim - * - * @return mixed */ public function __invoke($claim = null) { @@ -273,9 +252,7 @@ public function __invoke($claim = null) * @param string $method * @param array $parameters * - * @return mixed - * - * @throws BadMethodCallException + * @throws \BadMethodCallException */ public function __call($method, $parameters) { @@ -287,6 +264,6 @@ public function __call($method, $parameters) } } - throw new BadMethodCallException(sprintf('The claim [%s] does not exist on the payload.', Str::after($method, 'get'))); + throw new \BadMethodCallException(sprintf('The claim [%s] does not exist on the payload.', Str::after($method, 'get'))); } } diff --git a/src/Providers/Auth/Illuminate.php b/src/Providers/Auth/Illuminate.php index c923debe..1eb84433 100644 --- a/src/Providers/Auth/Illuminate.php +++ b/src/Providers/Auth/Illuminate.php @@ -47,8 +47,6 @@ public function byCredentials(array $credentials) /** * Authenticate a user via the id. * - * @param mixed $id - * * @return bool */ public function byId($id) @@ -58,8 +56,6 @@ public function byId($id) /** * Get the currently authenticated user. - * - * @return mixed */ public function user() { diff --git a/src/Providers/JWT/Lcobucci.php b/src/Providers/JWT/Lcobucci.php index 3c7d29d9..937c2371 100644 --- a/src/Providers/JWT/Lcobucci.php +++ b/src/Providers/JWT/Lcobucci.php @@ -12,8 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Providers\JWT; -use DateTimeImmutable; -use Exception; use Illuminate\Support\Collection; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Configuration; @@ -36,7 +34,6 @@ use PHPOpenSourceSaver\JWTAuth\Contracts\Providers\JWT; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; -use ReflectionClass; class Lcobucci extends Provider implements JWT { @@ -139,7 +136,7 @@ public function encode(array $payload) } return $this->builder->getToken($this->config->signer(), $this->config->signingKey())->toString(); - } catch (Exception $e) { + } catch (\Exception $e) { throw new JWTException('Could not create token: '.$e->getMessage(), $e->getCode(), $e); } } @@ -157,7 +154,7 @@ public function decode($token) { try { $jwt = $this->config->parser()->parse($token); - } catch (Exception $e) { + } catch (\Exception $e) { throw new TokenInvalidException('Could not decode token: '.$e->getMessage(), $e->getCode(), $e); } @@ -166,7 +163,7 @@ public function decode($token) } return (new Collection($jwt->claims()->all()))->map(function ($claim) { - if (is_a($claim, DateTimeImmutable::class)) { + if (is_a($claim, \DateTimeImmutable::class)) { return $claim->getTimestamp(); } if (is_object($claim) && method_exists($claim, 'getValue')) { @@ -181,7 +178,6 @@ public function decode($token) * Adds a claim to the {@see $config}. * * @param string $key - * @param mixed $value */ protected function addClaim($key, $value) { @@ -194,13 +190,13 @@ protected function addClaim($key, $value) $this->builder->identifiedBy($value); break; case RegisteredClaims::EXPIRATION_TIME: - $this->builder->expiresAt(DateTimeImmutable::createFromFormat('U', $value)); + $this->builder->expiresAt(\DateTimeImmutable::createFromFormat('U', $value)); break; case RegisteredClaims::NOT_BEFORE: - $this->builder->canOnlyBeUsedAfter(DateTimeImmutable::createFromFormat('U', $value)); + $this->builder->canOnlyBeUsedAfter(\DateTimeImmutable::createFromFormat('U', $value)); break; case RegisteredClaims::ISSUED_AT: - $this->builder->issuedAt(DateTimeImmutable::createFromFormat('U', $value)); + $this->builder->issuedAt(\DateTimeImmutable::createFromFormat('U', $value)); break; case RegisteredClaims::ISSUER: $this->builder->issuedBy($value); @@ -238,12 +234,9 @@ protected function getSigner() return new $signer(); } - /** - * {@inheritdoc} - */ protected function isAsymmetric() { - $reflect = new ReflectionClass($this->signer); + $reflect = new \ReflectionClass($this->signer); return $reflect->isSubclassOf(Rsa::class) || $reflect->isSubclassOf(Ecdsa::class); } diff --git a/src/Providers/JWT/Namshi.php b/src/Providers/JWT/Namshi.php index aaff119f..20c281b1 100644 --- a/src/Providers/JWT/Namshi.php +++ b/src/Providers/JWT/Namshi.php @@ -12,15 +12,11 @@ namespace PHPOpenSourceSaver\JWTAuth\Providers\JWT; -use Exception; -use InvalidArgumentException; use Namshi\JOSE\JWS; use Namshi\JOSE\Signer\OpenSSL\PublicKey; use PHPOpenSourceSaver\JWTAuth\Contracts\Providers\JWT; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; -use ReflectionClass; -use ReflectionException; class Namshi extends Provider implements JWT { @@ -59,7 +55,7 @@ public function encode(array $payload) $this->jws->setPayload($payload)->sign($this->getSigningKey(), $this->getPassphrase()); return (string) $this->jws->getTokenString(); - } catch (Exception $e) { + } catch (\Exception $e) { throw new JWTException('Could not create token: '.$e->getMessage(), $e->getCode(), $e); } } @@ -78,7 +74,7 @@ public function decode($token) try { // Let's never allow insecure tokens $jws = $this->jws->load($token, false); - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { throw new TokenInvalidException('Could not decode token: '.$e->getMessage(), $e->getCode(), $e); } @@ -89,14 +85,11 @@ public function decode($token) return (array) $jws->getPayload(); } - /** - * {@inheritdoc} - */ protected function isAsymmetric() { try { - return (new ReflectionClass(sprintf('Namshi\\JOSE\\Signer\\OpenSSL\\%s', $this->getAlgo())))->isSubclassOf(PublicKey::class); - } catch (ReflectionException $e) { + return (new \ReflectionClass(sprintf('Namshi\\JOSE\\Signer\\OpenSSL\\%s', $this->getAlgo())))->isSubclassOf(PublicKey::class); + } catch (\ReflectionException $e) { throw new JWTException('The given algorithm could not be found', $e->getCode(), $e); } } diff --git a/src/Providers/LaravelServiceProvider.php b/src/Providers/LaravelServiceProvider.php index b4a44f12..ccf73166 100644 --- a/src/Providers/LaravelServiceProvider.php +++ b/src/Providers/LaravelServiceProvider.php @@ -23,9 +23,6 @@ class LaravelServiceProvider extends AbstractServiceProvider { - /** - * {@inheritdoc} - */ public function boot() { $path = realpath(__DIR__.'/../../config/config.php'); @@ -55,9 +52,6 @@ public function boot() } } - /** - * {@inheritdoc} - */ protected function registerStorageProvider() { $this->app->singleton('tymon.jwt.provider.storage', function ($app) { diff --git a/src/Providers/LumenServiceProvider.php b/src/Providers/LumenServiceProvider.php index 3eb3a1d5..bff280f1 100644 --- a/src/Providers/LumenServiceProvider.php +++ b/src/Providers/LumenServiceProvider.php @@ -16,9 +16,6 @@ class LumenServiceProvider extends AbstractServiceProvider { - /** - * {@inheritdoc} - */ public function boot() { $this->app->configure('jwt'); diff --git a/src/Providers/Storage/Illuminate.php b/src/Providers/Storage/Illuminate.php index 47b73063..6c7f497d 100644 --- a/src/Providers/Storage/Illuminate.php +++ b/src/Providers/Storage/Illuminate.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Providers\Storage; -use BadMethodCallException; use Illuminate\Contracts\Cache\Repository as CacheContract; use PHPOpenSourceSaver\JWTAuth\Contracts\Providers\Storage; use Psr\SimpleCache\CacheInterface as PsrCacheInterface; @@ -22,7 +21,7 @@ class Illuminate implements Storage /** * The cache repository contract. * - * @var \Illuminate\Contracts\Cache\Repository + * @var CacheContract */ protected $cache; @@ -57,7 +56,6 @@ public function __construct(CacheContract $cache) * Add a new item into storage. * * @param string $key - * @param mixed $value * @param int $minutes * * @return void @@ -79,7 +77,6 @@ public function add($key, $value, $minutes) * Add a new item into storage forever. * * @param string $key - * @param mixed $value * * @return void */ @@ -92,8 +89,6 @@ public function forever($key, $value) * Get an item from storage. * * @param string $key - * - * @return mixed */ public function get($key) { @@ -125,7 +120,7 @@ public function flush() /** * Return the cache instance with tags attached. * - * @return \Illuminate\Contracts\Cache\Repository + * @return CacheContract */ protected function cache() { @@ -164,7 +159,7 @@ protected function determineTagSupport() // Attempt the repository tags command, which throws exceptions when unsupported $this->cache->tags($this->tag); $this->supportsTags = true; - } catch (BadMethodCallException $ex) { + } catch (\BadMethodCallException $ex) { $this->supportsTags = false; } } else { diff --git a/src/Validators/PayloadValidator.php b/src/Validators/PayloadValidator.php index e42321e7..b5d9d253 100644 --- a/src/Validators/PayloadValidator.php +++ b/src/Validators/PayloadValidator.php @@ -58,7 +58,7 @@ public function check($value) * * @return void * - * @throws \PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException + * @throws TokenInvalidException */ protected function validateStructure(Collection $claims) { @@ -72,7 +72,7 @@ protected function validateStructure(Collection $claims) * * @return Collection * - * @throws \PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException + * @throws TokenInvalidException * @throws \PHPOpenSourceSaver\JWTAuth\Exceptions\TokenExpiredException */ protected function validatePayload(Collection $claims) diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 604c5b51..fc34785b 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; use Carbon\Carbon; -use Mockery; use Yoast\PHPUnitPolyfills\TestCases\TestCase; abstract class AbstractTestCase extends TestCase @@ -34,7 +33,7 @@ public function setUp(): void public function tearDown(): void { Carbon::setTestNow(); - Mockery::close(); + \Mockery::close(); parent::tearDown(); } diff --git a/tests/BlacklistTest.php b/tests/BlacklistTest.php index de91b5f7..a178e0eb 100644 --- a/tests/BlacklistTest.php +++ b/tests/BlacklistTest.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Blacklist; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; @@ -38,9 +37,9 @@ public function setUp(): void { parent::setUp(); - $this->storage = Mockery::mock(Storage::class); + $this->storage = \Mockery::mock(Storage::class); $this->blacklist = new Blacklist($this->storage); - $this->validator = Mockery::mock(PayloadValidator::class); + $this->validator = \Mockery::mock(PayloadValidator::class); } /** @test */ @@ -193,9 +192,8 @@ public function blacklist_provider() /** * @test - * @dataProvider blacklist_provider * - * @param mixed $result + * @dataProvider blacklist_provider */ public function itShouldCheckWhetherATokenHasNotBeenBlacklisted($result) { diff --git a/tests/Claims/DatetimeClaimTest.php b/tests/Claims/DatetimeClaimTest.php index b47609b8..52475822 100644 --- a/tests/Claims/DatetimeClaimTest.php +++ b/tests/Claims/DatetimeClaimTest.php @@ -13,11 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Claims; use Carbon\Carbon; -use DateInterval; -use DateTime; -use DateTimeImmutable; -use DateTimeInterface; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Claims\Expiration; @@ -44,7 +39,7 @@ public function setUp(): void { parent::setUp(); - $this->validator = Mockery::mock(PayloadValidator::class); + $this->validator = \Mockery::mock(PayloadValidator::class); $this->validator->shouldReceive('setRefreshFlow->check'); $this->claimsTimestamp = [ @@ -66,8 +61,8 @@ public function itShouldHandleCarbonClaims() $testCarbonCopy = clone $testCarbon; $this->assertInstanceOf(Carbon::class, $testCarbon); - $this->assertInstanceOf(Datetime::class, $testCarbon); - $this->assertInstanceOf(DatetimeInterface::class, $testCarbon); + $this->assertInstanceOf(\DateTime::class, $testCarbon); + $this->assertInstanceOf(\DateTimeInterface::class, $testCarbon); $claimsDatetime = [ 'sub' => new Subject(1), @@ -87,11 +82,11 @@ public function itShouldHandleCarbonClaims() /** @test */ public function itShouldHandleDatetimeClaims() { - $testDateTime = DateTime::createFromFormat('U', $this->testNowTimestamp); + $testDateTime = \DateTime::createFromFormat('U', $this->testNowTimestamp); $testDateTimeCopy = clone $testDateTime; - $this->assertInstanceOf(DateTime::class, $testDateTime); - $this->assertInstanceOf(DatetimeInterface::class, $testDateTime); + $this->assertInstanceOf(\DateTime::class, $testDateTime); + $this->assertInstanceOf(\DateTimeInterface::class, $testDateTime); $claimsDatetime = [ 'sub' => new Subject(1), @@ -111,10 +106,10 @@ public function itShouldHandleDatetimeClaims() /** @test */ public function itShouldHandleDatetimeImmutableClaims() { - $testDateTimeImmutable = DateTimeImmutable::createFromFormat('U', (string) $this->testNowTimestamp); + $testDateTimeImmutable = \DateTimeImmutable::createFromFormat('U', (string) $this->testNowTimestamp); - $this->assertInstanceOf(DateTimeImmutable::class, $testDateTimeImmutable); - $this->assertInstanceOf(DatetimeInterface::class, $testDateTimeImmutable); + $this->assertInstanceOf(\DateTimeImmutable::class, $testDateTimeImmutable); + $this->assertInstanceOf(\DateTimeInterface::class, $testDateTimeImmutable); $claimsDatetime = [ 'sub' => new Subject(1), @@ -136,9 +131,9 @@ public function itShouldHandleDatetimeImmutableClaims() */ public function itShouldHandleDatetintervalClaims() { - $testDateInterval = new DateInterval('PT1H'); + $testDateInterval = new \DateInterval('PT1H'); - $this->assertInstanceOf(DateInterval::class, $testDateInterval); + $this->assertInstanceOf(\DateInterval::class, $testDateInterval); $claimsDateInterval = [ 'sub' => new Subject(1), diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index bf1d808e..277bcfe8 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Claims\Custom; @@ -40,8 +39,8 @@ public function setUp(): void { parent::setUp(); - $this->claimFactory = Mockery::mock(ClaimFactory::class); - $this->validator = Mockery::mock(PayloadValidator::class); + $this->claimFactory = \Mockery::mock(ClaimFactory::class); + $this->validator = \Mockery::mock(PayloadValidator::class); $this->factory = new Factory($this->claimFactory, $this->validator); } diff --git a/tests/Fixtures/Foo.php b/tests/Fixtures/Foo.php index a5a17705..038ef27b 100644 --- a/tests/Fixtures/Foo.php +++ b/tests/Fixtures/Foo.php @@ -16,8 +16,5 @@ class Foo extends Claim { - /** - * {@inheritdoc} - */ protected $name = 'foo'; } diff --git a/tests/Http/ParserTest.php b/tests/Http/ParserTest.php index 916dcf2f..d0b908c1 100644 --- a/tests/Http/ParserTest.php +++ b/tests/Http/ParserTest.php @@ -16,7 +16,6 @@ use Illuminate\Http\Request; use Illuminate\Routing\Route; use Illuminate\Support\Facades\Crypt; -use Mockery; use PHPOpenSourceSaver\JWTAuth\Contracts\Http\Parser as ParserContract; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Parser\AuthHeaders; @@ -132,6 +131,7 @@ public function itShouldNotStripTrailingHyphensFromTheAuthorizationHeader() /** * @test + * * @dataProvider whitespaceProvider */ public function itShouldHandleExcessWhitespaceFromTheAuthorizationHeader($whitespace) @@ -360,7 +360,7 @@ public function itShouldReturnTheTokenFromRoute() protected function getRouteMock($expectedParameterValue = null, $expectedParameterName = 'token') { - return Mockery::mock(Route::class) + return \Mockery::mock(Route::class) ->shouldReceive('parameter') ->with($expectedParameterName) ->andReturn($expectedParameterValue) @@ -468,7 +468,7 @@ public function itShouldRetrieveTheChain() new RouteParams(), ]; - $parser = new Parser(Mockery::mock(Request::class)); + $parser = new Parser(\Mockery::mock(Request::class)); $parser->setChain($chain); $this->assertSame($parser->getChain(), $chain); @@ -485,7 +485,7 @@ public function itShouldRetrieveTheChainWithAlias() ]; /* @var Request $request */ - $request = Mockery::mock(Request::class); + $request = \Mockery::mock(Request::class); $parser = new Parser($request); $parser->setChainOrder($chain); @@ -505,7 +505,7 @@ public function itShouldAddCustomParser() { $request = Request::create('foo', 'GET', ['foo' => 'bar']); - $customParser = Mockery::mock(ParserContract::class); + $customParser = \Mockery::mock(ParserContract::class); $customParser->shouldReceive('parse')->with($request)->andReturn('foobar'); $parser = new Parser($request); @@ -520,10 +520,10 @@ public function itShouldAddMultipleCustomParser() { $request = Request::create('foo', 'GET', ['foo' => 'bar']); - $customParser1 = Mockery::mock(ParserContract::class); + $customParser1 = \Mockery::mock(ParserContract::class); $customParser1->shouldReceive('parse')->with($request)->andReturn(false); - $customParser2 = Mockery::mock(ParserContract::class); + $customParser2 = \Mockery::mock(ParserContract::class); $customParser2->shouldReceive('parse')->with($request)->andReturn('foobar'); $parser = new Parser($request); diff --git a/tests/JWTAuthTest.php b/tests/JWTAuthTest.php index 0e579d5f..6e4d62fa 100644 --- a/tests/JWTAuthTest.php +++ b/tests/JWTAuthTest.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; use Illuminate\Http\Request; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Contracts\Providers\Auth; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; @@ -25,7 +24,6 @@ use PHPOpenSourceSaver\JWTAuth\Payload; use PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub; use PHPOpenSourceSaver\JWTAuth\Token; -use stdClass; class JWTAuthTest extends AbstractTestCase { @@ -39,17 +37,17 @@ class JWTAuthTest extends AbstractTestCase public function setUp(): void { - $this->manager = Mockery::mock(Manager::class); - $this->auth = Mockery::mock(Auth::class); - $this->parser = Mockery::mock(Parser::class); + $this->manager = \Mockery::mock(Manager::class); + $this->auth = \Mockery::mock(Auth::class); + $this->parser = \Mockery::mock(Parser::class); $this->jwtAuth = new JWTAuth($this->manager, $this->auth, $this->parser); } /** @test */ public function itShouldReturnATokenWhenPassingAUser() { - $payloadFactory = Mockery::mock(Factory::class); - $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); + $payloadFactory = \Mockery::mock(Factory::class); + $payloadFactory->shouldReceive('make')->andReturn(\Mockery::mock(Payload::class)); $this->manager ->shouldReceive('getPayloadFactory->customClaims') @@ -67,8 +65,8 @@ public function itShouldReturnATokenWhenPassingAUser() /** @test */ public function itShouldPassProviderCheckIfHashMatches() { - $payloadFactory = Mockery::mock(Factory::class); - $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); + $payloadFactory = \Mockery::mock(Factory::class); + $payloadFactory->shouldReceive('make')->andReturn(\Mockery::mock(Payload::class)); $payloadFactory->shouldReceive('get') ->with('prv') ->andReturn(sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub')); @@ -81,8 +79,8 @@ public function itShouldPassProviderCheckIfHashMatches() /** @test */ public function itShouldPassProviderCheckIfHashMatchesWhenProviderIsNull() { - $payloadFactory = Mockery::mock(Factory::class); - $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); + $payloadFactory = \Mockery::mock(Factory::class); + $payloadFactory->shouldReceive('make')->andReturn(\Mockery::mock(Payload::class)); $payloadFactory->shouldReceive('get') ->with('prv') ->andReturnNull(); @@ -95,8 +93,8 @@ public function itShouldPassProviderCheckIfHashMatchesWhenProviderIsNull() /** @test */ public function itShouldNotPassProviderCheckIfHashNotMatch() { - $payloadFactory = Mockery::mock(Factory::class); - $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); + $payloadFactory = \Mockery::mock(Factory::class); + $payloadFactory->shouldReceive('make')->andReturn(\Mockery::mock(Payload::class)); $payloadFactory->shouldReceive('get') ->with('prv') ->andReturn(sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub1')); @@ -109,8 +107,8 @@ public function itShouldNotPassProviderCheckIfHashNotMatch() /** @test */ public function itShouldReturnATokenWhenPassingValidCredentialsToAttemptMethod() { - $payloadFactory = Mockery::mock(Factory::class); - $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); + $payloadFactory = \Mockery::mock(Factory::class); + $payloadFactory->shouldReceive('make')->andReturn(\Mockery::mock(Payload::class)); $this->manager ->shouldReceive('getPayloadFactory->customClaims') @@ -152,7 +150,7 @@ public function itShouldThrowAnExceptionWhenNotProvidingAToken() /** @test */ public function itShouldReturnTheOwningUserFromATokenContainingAnExistingUser() { - $payload = Mockery::mock(Payload::class); + $payload = \Mockery::mock(Payload::class); $payload->shouldReceive('get')->once()->with('sub')->andReturn(1); $this->manager->shouldReceive('decode')->once()->andReturn($payload); @@ -168,7 +166,7 @@ public function itShouldReturnTheOwningUserFromATokenContainingAnExistingUser() /** @test */ public function itShouldReturnFalseWhenPassingATokenNotContainingAnExistingUser() { - $payload = Mockery::mock(Payload::class); + $payload = \Mockery::mock(Payload::class); $payload->shouldReceive('get')->once()->with('sub')->andReturn(1); $this->manager->shouldReceive('decode')->once()->andReturn($payload); @@ -184,7 +182,7 @@ public function itShouldReturnFalseWhenPassingATokenNotContainingAnExistingUser( /** @test */ public function itShouldRefreshAToken() { - $newToken = Mockery::mock(Token::class); + $newToken = \Mockery::mock(Token::class); $newToken->shouldReceive('get')->once()->andReturn('baz.bar.foo'); $this->manager->shouldReceive('customClaims->refresh')->once()->andReturn($newToken); @@ -242,7 +240,7 @@ public function itShouldReturnFalseIfTheTokenIsInvalid() /** @test */ public function itShouldReturnTrueIfTheTokenIsValid() { - $payload = Mockery::mock(Payload::class); + $payload = \Mockery::mock(Payload::class); $this->parser->shouldReceive('parseToken')->andReturn('foo.bar.baz'); $this->manager->shouldReceive('decode')->once()->andReturn($payload); @@ -272,11 +270,11 @@ public function itShouldReturnFalseWhenNoTokenIsSet() /** @test */ public function itShouldMagicallyCallTheManager() { - $this->manager->shouldReceive('getBlacklist')->andReturn(new stdClass()); + $this->manager->shouldReceive('getBlacklist')->andReturn(new \stdClass()); $blacklist = $this->jwtAuth->manager()->getBlacklist(); - $this->assertInstanceOf(stdClass::class, $blacklist); + $this->assertInstanceOf(\stdClass::class, $blacklist); } /** @test */ @@ -321,7 +319,7 @@ public function itShouldGetTheParserInstance() /** @test */ public function itShouldGetAClaimValue() { - $payload = Mockery::mock(Payload::class); + $payload = \Mockery::mock(Payload::class); $payload->shouldReceive('get')->once()->with('sub')->andReturn(1); $this->manager->shouldReceive('decode')->once()->andReturn($payload); diff --git a/tests/JWTGuardTest.php b/tests/JWTGuardTest.php index 7be48087..5f6e0442 100644 --- a/tests/JWTGuardTest.php +++ b/tests/JWTGuardTest.php @@ -20,7 +20,6 @@ use Illuminate\Auth\Events\Logout; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Http\Request; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\UserNotDefinedException; @@ -44,9 +43,9 @@ public function setUp(): void { parent::setUp(); - $this->jwt = Mockery::mock(JWT::class); - $this->provider = Mockery::mock(EloquentUserProvider::class); - $this->eventDispatcher = Mockery::mock(Dispatcher::class); + $this->jwt = \Mockery::mock(JWT::class); + $this->provider = \Mockery::mock(EloquentUserProvider::class); + $this->eventDispatcher = \Mockery::mock(Dispatcher::class); $this->guard = new JWTGuard( $this->jwt, $this->provider, @@ -64,7 +63,7 @@ public function itShouldGetTheRequest() /** @test */ public function itShouldGetTheAuthenticatedUserIfAValidTokenIsProvided() { - $payload = Mockery::mock(Payload::class); + $payload = \Mockery::mock(Payload::class); $payload->shouldReceive('offsetGet')->once()->with('sub')->andReturn(1); $this->jwt->shouldReceive('setRequest')->andReturn($this->jwt); @@ -96,7 +95,7 @@ public function itShouldGetTheAuthenticatedUserIfAValidTokenIsProvided() /** @test */ public function itShouldGetTheAuthenticatedUserIfAValidTokenIsProvidedAndNotThrowAnException() { - $payload = Mockery::mock(Payload::class); + $payload = \Mockery::mock(Payload::class); $payload->shouldReceive('offsetGet')->once()->with('sub')->andReturn(1); $this->jwt->shouldReceive('setRequest')->andReturn($this->jwt); @@ -213,21 +212,21 @@ public function itShouldReturnATokenIfCredentialsAreOkAndUserIsFound() $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Attempting::class)); + ->with(\Mockery::type(Attempting::class)); if (class_exists('Illuminate\Auth\Events\Validated')) { $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type('Illuminate\Auth\Events\Validated')); + ->with(\Mockery::type('Illuminate\Auth\Events\Validated')); } $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Login::class)); + ->with(\Mockery::type(Login::class)); $token = $this->guard->claims(['foo' => 'bar'])->attempt($credentials); @@ -253,21 +252,21 @@ public function itShouldReturnTrueIfCredentialsAreOkAndUserIsFoundWhenChoosingNo $this->eventDispatcher->shouldReceive('dispatch') ->twice() - ->with(Mockery::type(Attempting::class)); + ->with(\Mockery::type(Attempting::class)); if (class_exists('Illuminate\Auth\Events\Validated')) { $this->eventDispatcher->shouldReceive('dispatch') ->twice() - ->with(Mockery::type('Illuminate\Auth\Events\Validated')); + ->with(\Mockery::type('Illuminate\Auth\Events\Validated')); } $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Login::class)); + ->with(\Mockery::type(Login::class)); $this->assertTrue($this->guard->attempt($credentials, false)); // once $this->assertTrue($this->guard->validate($credentials)); // twice @@ -291,19 +290,19 @@ public function itShouldReturnFalseIfCredentialsAreInvalid() $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Attempting::class)); + ->with(\Mockery::type(Attempting::class)); $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Failed::class)); + ->with(\Mockery::type(Failed::class)); $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Login::class)); + ->with(\Mockery::type(Login::class)); $this->assertFalse($this->guard->attempt($credentials)); } @@ -311,7 +310,7 @@ public function itShouldReturnFalseIfCredentialsAreInvalid() /** @test */ public function itShouldMagicallyCallTheJwtInstance() { - $this->jwt->shouldReceive('factory')->andReturn(Mockery::mock(Factory::class)); + $this->jwt->shouldReceive('factory')->andReturn(\Mockery::mock(Factory::class)); $this->assertInstanceOf(Factory::class, $this->guard->factory()); } @@ -325,11 +324,11 @@ public function itShouldLogoutTheUserByInvalidatingTheToken() $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Logout::class)); + ->with(\Mockery::type(Logout::class)); $this->guard->logout(); $this->assertNull($this->guard->getUser()); @@ -385,11 +384,11 @@ public function itShouldGenerateATokenById() $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Login::class)); + ->with(\Mockery::type(Login::class)); $this->assertSame('foo.bar.baz', $this->guard->tokenById(1)); } @@ -423,21 +422,21 @@ public function itShouldAuthenticateTheUserByCredentialsAndReturnTrueIfValid() $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Attempting::class)); + ->with(\Mockery::type(Attempting::class)); if (class_exists('Illuminate\Auth\Events\Validated')) { $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type('Illuminate\Auth\Events\Validated')); + ->with(\Mockery::type('Illuminate\Auth\Events\Validated')); } $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->never() - ->with(Mockery::type(Login::class)); + ->with(\Mockery::type(Login::class)); $this->assertTrue($this->guard->once($credentials)); } @@ -460,11 +459,11 @@ public function itShouldAttemptToAuthenticateTheUserByCredentialsAndReturnFalseI $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Attempting::class)); + ->with(\Mockery::type(Attempting::class)); $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Failed::class)); + ->with(\Mockery::type(Failed::class)); $this->assertFalse($this->guard->once($credentials)); } @@ -481,7 +480,7 @@ public function itShouldAuthenticateTheUserByIdAndReturnBoolean() $this->eventDispatcher->shouldReceive('dispatch') ->twice() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->assertTrue($this->guard->onceUsingId(1)); // once $this->assertTrue($this->guard->byId(1)); // twice @@ -516,11 +515,11 @@ public function itShouldCreateATokenFromAUserObject() $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Authenticated::class)); + ->with(\Mockery::type(Authenticated::class)); $this->eventDispatcher->shouldReceive('dispatch') ->once() - ->with(Mockery::type(Login::class)); + ->with(\Mockery::type(Login::class)); $token = $this->guard->login($user); @@ -532,7 +531,7 @@ public function itShouldGetThePayload() { $this->jwt->shouldReceive('setRequest')->andReturn($this->jwt); $this->jwt->shouldReceive('getToken')->once()->andReturn('foo.bar.baz'); - $this->jwt->shouldReceive('getPayload')->once()->andReturn(Mockery::mock(Payload::class)); + $this->jwt->shouldReceive('getPayload')->once()->andReturn(\Mockery::mock(Payload::class)); $this->assertInstanceOf(Payload::class, $this->guard->payload()); } diff --git a/tests/ManagerTest.php b/tests/ManagerTest.php index 8dfb3944..79d41b14 100644 --- a/tests/ManagerTest.php +++ b/tests/ManagerTest.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Blacklist; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; @@ -48,11 +47,11 @@ public function setUp(): void { parent::setUp(); - $this->jwt = Mockery::mock(JWT::class); - $this->blacklist = Mockery::mock(Blacklist::class); - $this->factory = Mockery::mock(Factory::class); + $this->jwt = \Mockery::mock(JWT::class); + $this->blacklist = \Mockery::mock(Blacklist::class); + $this->factory = \Mockery::mock(Factory::class); $this->manager = new Manager($this->jwt, $this->blacklist, $this->factory); - $this->validator = Mockery::mock(PayloadValidator::class); + $this->validator = \Mockery::mock(PayloadValidator::class); } /** @test diff --git a/tests/Middleware/AbstractMiddlewareTest.php b/tests/Middleware/AbstractMiddlewareTest.php index a8520216..2e677a99 100644 --- a/tests/Middleware/AbstractMiddlewareTest.php +++ b/tests/Middleware/AbstractMiddlewareTest.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Middleware; use Illuminate\Http\Request; -use Mockery; use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\JWTAuth; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; @@ -34,7 +33,7 @@ public function setUp(): void { parent::setUp(); - $this->auth = Mockery::mock(JWTAuth::class); - $this->request = Mockery::mock(Request::class); + $this->auth = \Mockery::mock(JWTAuth::class); + $this->request = \Mockery::mock(Request::class); } } diff --git a/tests/Middleware/AuthenticateAndRenewTest.php b/tests/Middleware/AuthenticateAndRenewTest.php index efa07b3d..d33f202c 100644 --- a/tests/Middleware/AuthenticateAndRenewTest.php +++ b/tests/Middleware/AuthenticateAndRenewTest.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Middleware; use Illuminate\Http\Response; -use Mockery; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\Authenticate; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\AuthenticateAndRenew; @@ -38,7 +37,7 @@ public function setUp(): void /** @test */ public function itShouldAuthenticateAUserAndReturnANewToken() { - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); $this->auth->parser()->shouldReceive('setRequest')->once()->with($this->request)->andReturn($this->auth->parser()); @@ -59,7 +58,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfTokenNotProvided() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(false); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -74,7 +73,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfTokenInvalid() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); diff --git a/tests/Middleware/AuthenticateTest.php b/tests/Middleware/AuthenticateTest.php index c1d575e1..c8c2c583 100644 --- a/tests/Middleware/AuthenticateTest.php +++ b/tests/Middleware/AuthenticateTest.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Middleware; -use Mockery; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\Authenticate; use PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser; @@ -36,7 +35,7 @@ public function setUp(): void /** @test */ public function itShouldAuthenticateAUser() { - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -53,7 +52,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfTokenNotProvided() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(false); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -68,7 +67,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfTokenInvalid() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -85,7 +84,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfUserNotFound() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); diff --git a/tests/Middleware/CheckTest.php b/tests/Middleware/CheckTest.php index 0184dab3..01886b84 100644 --- a/tests/Middleware/CheckTest.php +++ b/tests/Middleware/CheckTest.php @@ -12,7 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Middleware; -use Mockery; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\Check; use PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser; @@ -35,7 +34,7 @@ public function setUp(): void /** @test */ public function itShouldAuthenticateAUserIfATokenIsPresent() { - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -50,7 +49,7 @@ public function itShouldAuthenticateAUserIfATokenIsPresent() /** @test */ public function itShouldUnsetTheExceptionIfATokenIsPresent() { - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -65,7 +64,7 @@ public function itShouldUnsetTheExceptionIfATokenIsPresent() /** @test */ public function itShouldDoNothingIfATokenIsNotPresent() { - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(false); $this->auth->shouldReceive('parser')->andReturn($parser); diff --git a/tests/Middleware/RefreshTokenTest.php b/tests/Middleware/RefreshTokenTest.php index 7fadcc42..e4454fc0 100644 --- a/tests/Middleware/RefreshTokenTest.php +++ b/tests/Middleware/RefreshTokenTest.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Middleware; use Illuminate\Http\Response; -use Mockery; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\RefreshToken; use PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser; @@ -36,7 +35,7 @@ public function setUp(): void /** @test */ public function itShouldRefreshAToken() { - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -56,7 +55,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfTokenNotProvided() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(false); $this->auth->shouldReceive('parser')->andReturn($parser); @@ -71,7 +70,7 @@ public function itShouldThrowAnUnauthorizedExceptionIfTokenInvalid() { $this->expectException(UnauthorizedHttpException::class); - $parser = Mockery::mock(Parser::class); + $parser = \Mockery::mock(Parser::class); $parser->shouldReceive('hasToken')->once()->andReturn(true); $this->auth->shouldReceive('parser')->andReturn($parser); diff --git a/tests/PayloadTest.php b/tests/PayloadTest.php index bc508569..ebc5bee6 100644 --- a/tests/PayloadTest.php +++ b/tests/PayloadTest.php @@ -12,8 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; -use BadMethodCallException; -use Mockery; use Mockery\LegacyMockInterface; use PHPOpenSourceSaver\JWTAuth\Claims\Audience; use PHPOpenSourceSaver\JWTAuth\Claims\Claim; @@ -67,7 +65,7 @@ private function getTestPayload(array $extraClaims = []) $collection = Collection::make($claims); - $this->validator = Mockery::mock(PayloadValidator::class); + $this->validator = \Mockery::mock(PayloadValidator::class); $this->validator->shouldReceive('setRefreshFlow->check')->andReturn($collection); return new Payload($collection, $this->validator); @@ -169,7 +167,7 @@ public function itShouldInvokeTheInstanceAsACallable() /** @test */ public function itShouldThrowAnExceptionWhenMagicallyGettingAPropertyThatDoesNotExist() { - $this->expectException(BadMethodCallException::class); + $this->expectException(\BadMethodCallException::class); $this->expectExceptionMessage('The claim [Foo] does not exist on the payload'); $this->payload->getFoo(); diff --git a/tests/Providers/Auth/IlluminateTest.php b/tests/Providers/Auth/IlluminateTest.php index a34b88f3..566dfe1d 100644 --- a/tests/Providers/Auth/IlluminateTest.php +++ b/tests/Providers/Auth/IlluminateTest.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Providers\Auth; use Illuminate\Contracts\Auth\Guard; -use Mockery; use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Providers\Auth\Illuminate as Auth; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; @@ -34,7 +33,7 @@ public function setUp(): void { parent::setUp(); - $this->authManager = Mockery::mock(Guard::class); + $this->authManager = \Mockery::mock(Guard::class); $this->auth = new Auth($this->authManager); } diff --git a/tests/Providers/JWT/LcobucciTest.php b/tests/Providers/JWT/LcobucciTest.php index 583e83a4..6413922f 100644 --- a/tests/Providers/JWT/LcobucciTest.php +++ b/tests/Providers/JWT/LcobucciTest.php @@ -12,8 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Providers\JWT; -use Exception; -use InvalidArgumentException; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Parser; use Lcobucci\JWT\Signer; @@ -22,7 +20,6 @@ use Lcobucci\JWT\Token; use Lcobucci\JWT\Token\DataSet; use Lcobucci\JWT\Validation\Constraint; -use Mockery; use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; @@ -57,8 +54,8 @@ public function setUp(): void { parent::setUp(); - $this->builder = Mockery::mock(Builder::class); - $this->parser = Mockery::mock(Parser::class); + $this->builder = \Mockery::mock(Builder::class); + $this->parser = \Mockery::mock(Parser::class); } /** @test */ @@ -100,7 +97,7 @@ public function itShouldThrowAnInvalidExceptionWhenThePayloadCouldNotBeEncoded() ->shouldReceive('getToken') ->once() ->with(\Mockery::type(Signer::class), \Mockery::type(Key::class)) - ->andThrow(new Exception()); + ->andThrow(new \Exception()); $this->getProvider('secret', 'HS256')->encode($payload); } @@ -110,13 +107,13 @@ public function itShouldReturnThePayloadWhenPassingAValidTokenToDecode() { $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp + 3600, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $token = Mockery::mock(Token::class); - $dataSet = Mockery::mock(new DataSet($payload, 'payload')); + $token = \Mockery::mock(Token::class); + $dataSet = \Mockery::mock(new DataSet($payload, 'payload')); $provider = $this->getProvider('secret', 'HS256'); $this->parser->shouldReceive('parse')->once()->with('foo.bar.baz')->andReturn($token); - $this->validator->shouldReceive('validate')->once()->with($token, Mockery::any())->andReturnTrue(); + $this->validator->shouldReceive('validate')->once()->with($token, \Mockery::any())->andReturnTrue(); $token->shouldReceive('claims')->once()->andReturn($dataSet); $dataSet->shouldReceive('all')->once()->andReturn($payload); @@ -126,8 +123,8 @@ public function itShouldReturnThePayloadWhenPassingAValidTokenToDecode() /** @test */ public function itShouldThrowATokenInvalidExceptionWhenTheTokenCouldNotBeDecodedDueToABadSignature() { - $token = Mockery::mock(Token::class); - $dataSet = Mockery::mock(new DataSet(['pay', 'load'], 'payload')); + $token = \Mockery::mock(Token::class); + $dataSet = \Mockery::mock(new DataSet(['pay', 'load'], 'payload')); $provider = $this->getProvider('secret', 'HS256'); @@ -135,7 +132,7 @@ public function itShouldThrowATokenInvalidExceptionWhenTheTokenCouldNotBeDecoded $this->expectExceptionMessage('Token Signature could not be verified.'); $this->parser->shouldReceive('parse')->once()->with('foo.bar.baz')->andReturn($token); - $this->validator->shouldReceive('validate')->once()->with($token, Mockery::any())->andReturnFalse(); + $this->validator->shouldReceive('validate')->once()->with($token, \Mockery::any())->andReturnFalse(); $token->shouldReceive('claims')->never(); $dataSet->shouldReceive('all')->never(); @@ -148,7 +145,7 @@ public function itShouldThrowATokenInvalidExceptionWhenTheTokenCouldNotBeDecoded $this->expectException(TokenInvalidException::class); $this->expectExceptionMessage('Could not decode token:'); - $this->parser->shouldReceive('parse')->once()->with('foo.bar.baz')->andThrow(new InvalidArgumentException()); + $this->parser->shouldReceive('parse')->once()->with('foo.bar.baz')->andThrow(new \InvalidArgumentException()); $this->parser->shouldReceive('verify')->never(); $this->parser->shouldReceive('getClaims')->never(); @@ -178,7 +175,7 @@ public function itShouldGenerateATokenWhenUsingAnRsaAlgorithm() $this->builder ->shouldReceive('getToken') ->once() - ->with(Mockery::type(RS256::class), Mockery::type(Key::class)) + ->with(\Mockery::type(RS256::class), \Mockery::type(Key::class)) ->andReturn(new Token\Plain(new DataSet([], 'header'), $dataSet, new Token\Signature('', 'signature'))); $token = $provider->encode($payload); @@ -238,8 +235,8 @@ public function getProvider($secret, $algo, array $keys = []) { $provider = new Lcobucci($secret, $algo, $keys); - $this->validator = Mockery::mock(\Lcobucci\JWT\Validator::class); - $this->config = Mockery::mock($provider->getConfig()); + $this->validator = \Mockery::mock(\Lcobucci\JWT\Validator::class); + $this->config = \Mockery::mock($provider->getConfig()); $provider = new Lcobucci($secret, $algo, $keys, $this->config); @@ -247,7 +244,7 @@ public function getProvider($secret, $algo, array $keys = []) $this->config->shouldReceive('parser')->andReturn($this->parser); $this->config->shouldReceive('validator')->andReturn($this->validator); - $constraint = Mockery::mock(Constraint::class); + $constraint = \Mockery::mock(Constraint::class); $constraint->shouldReceive('assert')->andReturn(); $this->config->shouldReceive('validationConstraints')->andReturn([$constraint]); diff --git a/tests/Providers/JWT/NamshiTest.php b/tests/Providers/JWT/NamshiTest.php index 9fa25790..36f83e04 100644 --- a/tests/Providers/JWT/NamshiTest.php +++ b/tests/Providers/JWT/NamshiTest.php @@ -12,9 +12,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Providers\JWT; -use Exception; -use InvalidArgumentException; -use Mockery; use Mockery\MockInterface; use Namshi\JOSE\JWS; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; @@ -38,7 +35,7 @@ public function setUp(): void { parent::setUp(); - $this->jws = Mockery::mock(JWS::class); + $this->jws = \Mockery::mock(JWS::class); } /** @test */ @@ -46,8 +43,8 @@ public function itShouldReturnTheTokenWhenPassingAValidPayloadToEncode() { $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp + 3600, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(Mockery::self()); - $this->jws->shouldReceive('sign')->once()->with('secret', null)->andReturn(Mockery::self()); + $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(\Mockery::self()); + $this->jws->shouldReceive('sign')->once()->with('secret', null)->andReturn(\Mockery::self()); $this->jws->shouldReceive('getTokenString')->once()->andReturn('foo.bar.baz'); $token = $this->getProvider('secret', 'HS256')->encode($payload); @@ -68,8 +65,8 @@ public function itShouldThrowAnInvalidExceptionWhenThePayloadCouldNotBeEncoded() $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(Mockery::self()); - $this->jws->shouldReceive('sign')->andThrow(new Exception()); + $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(\Mockery::self()); + $this->jws->shouldReceive('sign')->andThrow(new \Exception()); $this->getProvider('secret', 'HS256')->encode($payload); } @@ -79,7 +76,7 @@ public function itShouldReturnThePayloadWhenPassingAValidTokenToDecode() { $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp + 3600, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andReturn(Mockery::self()); + $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andReturn(\Mockery::self()); $this->jws->shouldReceive('verify')->once()->with('secret', 'HS256')->andReturn(true); $this->jws->shouldReceive('getPayload')->andReturn($payload); @@ -92,7 +89,7 @@ public function itShouldThrowATokenInvalidExceptionWhenTheTokenCouldNotBeDecoded $this->expectException(TokenInvalidException::class); $this->expectExceptionMessage('Token Signature could not be verified.'); - $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andReturn(Mockery::self()); + $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andReturn(\Mockery::self()); $this->jws->shouldReceive('verify')->once()->with('secret', 'HS256')->andReturn(false); $this->jws->shouldReceive('getPayload')->never(); @@ -105,7 +102,7 @@ public function itShouldThrowATokenInvalidExceptionWhenTheTokenCouldNotBeDecoded $this->expectException(TokenInvalidException::class); $this->expectExceptionMessage('Could not decode token:'); - $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andThrow(new InvalidArgumentException()); + $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andThrow(new \InvalidArgumentException()); $this->jws->shouldReceive('verify')->never(); $this->jws->shouldReceive('getPayload')->never(); @@ -123,8 +120,8 @@ public function itShouldGenerateATokenWhenUsingAnRsaAlgorithm() $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp + 3600, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(Mockery::self()); - $this->jws->shouldReceive('sign')->once()->with($this->getDummyPrivateKey(), null)->andReturn(Mockery::self()); + $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(\Mockery::self()); + $this->jws->shouldReceive('sign')->once()->with($this->getDummyPrivateKey(), null)->andReturn(\Mockery::self()); $this->jws->shouldReceive('getTokenString')->once()->andReturn('foo.bar.baz'); $token = $provider->encode($payload); @@ -153,8 +150,8 @@ public function itShouldGenerateATokenWhenUsingAnEcdsaAlgorithm() $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp + 3600, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(Mockery::self()); - $this->jws->shouldReceive('sign')->once()->with($this->getDummyPrivateKey(), null)->andReturn(Mockery::self()); + $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(\Mockery::self()); + $this->jws->shouldReceive('sign')->once()->with($this->getDummyPrivateKey(), null)->andReturn(\Mockery::self()); $this->jws->shouldReceive('getTokenString')->once()->andReturn('foo.bar.baz'); $token = $provider->encode($payload); @@ -173,8 +170,8 @@ public function itShouldDecodeATokenWhenUsingAnRsaAlgorithm() $payload = ['sub' => 1, 'exp' => $this->testNowTimestamp + 3600, 'iat' => $this->testNowTimestamp, 'iss' => '/foo']; - $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(Mockery::self()); - $this->jws->shouldReceive('sign')->once()->with($this->getDummyPrivateKey(), null)->andReturn(Mockery::self()); + $this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(\Mockery::self()); + $this->jws->shouldReceive('sign')->once()->with($this->getDummyPrivateKey(), null)->andReturn(\Mockery::self()); $this->jws->shouldReceive('getTokenString')->once()->andReturn('foo.bar.baz'); $token = $provider->encode($payload); @@ -188,7 +185,7 @@ public function itShouldThrowAExceptionWhenTheAlgorithmPassedIsInvalid() $this->expectException(JWTException::class); $this->expectExceptionMessage('The given algorithm could not be found'); - $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andReturn(Mockery::self()); + $this->jws->shouldReceive('load')->once()->with('foo.bar.baz', false)->andReturn(\Mockery::self()); $this->jws->shouldReceive('verify')->with('secret', 'AlgorithmWrong')->andReturn(true); $this->getProvider('secret', 'AlgorithmWrong')->decode('foo.bar.baz'); diff --git a/tests/Providers/Storage/IlluminateTest.php b/tests/Providers/Storage/IlluminateTest.php index f2896e80..6e548c86 100644 --- a/tests/Providers/Storage/IlluminateTest.php +++ b/tests/Providers/Storage/IlluminateTest.php @@ -13,7 +13,6 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Providers\Storage; use Illuminate\Contracts\Cache\Repository; -use Mockery; use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Providers\Storage\Illuminate as Storage; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; @@ -35,7 +34,7 @@ public function setUp(): void { parent::setUp(); - $this->cache = Mockery::mock(Repository::class); + $this->cache = \Mockery::mock(Repository::class); $this->storage = new Storage($this->cache); } @@ -100,7 +99,7 @@ private function emulateTags() { $this->storage = new TaggedStorage($this->cache); - $this->cache->shouldReceive('tags')->with('tymon.jwt')->once()->andReturn(Mockery::self()); + $this->cache->shouldReceive('tags')->with('tymon.jwt')->once()->andReturn(\Mockery::self()); } /** @test */ diff --git a/tests/Stubs/JWTProviderStub.php b/tests/Stubs/JWTProviderStub.php index a323dec5..a5e64a79 100644 --- a/tests/Stubs/JWTProviderStub.php +++ b/tests/Stubs/JWTProviderStub.php @@ -16,9 +16,6 @@ class JWTProviderStub extends Provider { - /** - * {@inheritdoc} - */ protected function isAsymmetric() { return false; diff --git a/tests/Validators/TokenValidatorTest.php b/tests/Validators/TokenValidatorTest.php index 9a063955..2055bc06 100644 --- a/tests/Validators/TokenValidatorTest.php +++ b/tests/Validators/TokenValidatorTest.php @@ -38,6 +38,7 @@ public function itShouldReturnTrueWhenProvidingAWellFormedToken() /** * @test + * * @dataProvider \PHPOpenSourceSaver\JWTAuth\Test\Validators\TokenValidatorTest::dataProviderMalformedTokens * * @param string $token @@ -49,6 +50,7 @@ public function itShouldReturnFalseWhenProvidingAMalformedToken($token) /** * @test + * * @dataProvider \PHPOpenSourceSaver\JWTAuth\Test\Validators\TokenValidatorTest::dataProviderMalformedTokens */ public function itShouldThrowAnExceptionWhenProvidingAMalformedToken($token) @@ -61,6 +63,7 @@ public function itShouldThrowAnExceptionWhenProvidingAMalformedToken($token) /** * @test + * * @dataProvider \PHPOpenSourceSaver\JWTAuth\Test\Validators\TokenValidatorTest::dataProviderTokensWithWrongSegmentsNumber */ public function itShouldReturnFalseWhenProvidingATokenWithWrongSegmentsNumber($token) @@ -70,6 +73,7 @@ public function itShouldReturnFalseWhenProvidingATokenWithWrongSegmentsNumber($t /** * @test + * * @dataProvider \PHPOpenSourceSaver\JWTAuth\Test\Validators\TokenValidatorTest::dataProviderTokensWithWrongSegmentsNumber */ public function itShouldThrowAnExceptionWhenProvidingAMalformedTokenWithWrongSegmentsNumber($token)