diff --git a/.gitignore b/.gitignore index 187e79c..9729c46 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.lock build coverage.xml .phpunit.result.cache +.idea diff --git a/tests/BlacklistTest.php b/tests/BlacklistTest.php index f7a4119..b6e2996 100644 --- a/tests/BlacklistTest.php +++ b/tests/BlacklistTest.php @@ -12,6 +12,7 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Blacklist; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Claims\Expiration; @@ -23,21 +24,22 @@ use PHPOpenSourceSaver\JWTAuth\Contracts\Providers\Storage; use PHPOpenSourceSaver\JWTAuth\Payload; use PHPOpenSourceSaver\JWTAuth\Validators\PayloadValidator; +use PHPOpenSourceSaver\JWTAuth\Validators\Validator; class BlacklistTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Contracts\Providers\Storage|\Mockery\MockInterface + * @var Storage|MockInterface */ protected $storage; /** - * @var \PHPOpenSourceSaver\JWTAuth\Blacklist + * @var Blacklist */ protected $blacklist; /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Validators\Validator + * @var MockInterface|Validator */ protected $validator; diff --git a/tests/Claims/ClaimTest.php b/tests/Claims/ClaimTest.php index 1ce2ea7..dff097e 100644 --- a/tests/Claims/ClaimTest.php +++ b/tests/Claims/ClaimTest.php @@ -19,7 +19,7 @@ class ClaimTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Claims\Expiration + * @var Expiration */ protected $claim; @@ -48,7 +48,7 @@ public function it_should_convert_the_claim_to_an_array() /** @test */ public function it_should_get_the_claim_as_a_string() { - $this->assertJsonStringEqualsJsonString((string) $this->claim, $this->claim->toJson()); + $this->assertJsonStringEqualsJsonString((string)$this->claim, $this->claim->toJson()); } /** @test */ diff --git a/tests/Claims/CollectionTest.php b/tests/Claims/CollectionTest.php index da02a38..59419ae 100644 --- a/tests/Claims/CollectionTest.php +++ b/tests/Claims/CollectionTest.php @@ -22,6 +22,14 @@ class CollectionTest extends AbstractTestCase { + /** @test */ + public function it_should_sanitize_the_claims_to_associative_array() + { + $collection = $this->getCollection(); + + $this->assertSame(array_keys($collection->toArray()), ['sub', 'iss', 'exp', 'nbf', 'iat', 'jti']); + } + private function getCollection() { $claims = [ @@ -36,14 +44,6 @@ private function getCollection() return new Collection($claims); } - /** @test */ - public function it_should_sanitize_the_claims_to_associative_array() - { - $collection = $this->getCollection(); - - $this->assertSame(array_keys($collection->toArray()), ['sub', 'iss', 'exp', 'nbf', 'iat', 'jti']); - } - /** @test */ public function it_should_determine_if_a_collection_contains_all_the_given_claims() { diff --git a/tests/Claims/DatetimeClaimTest.php b/tests/Claims/DatetimeClaimTest.php index 16744e9..892184c 100644 --- a/tests/Claims/DatetimeClaimTest.php +++ b/tests/Claims/DatetimeClaimTest.php @@ -17,6 +17,7 @@ use DateTimeImmutable; use DateTimeInterface; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Claims\Expiration; use PHPOpenSourceSaver\JWTAuth\Claims\IssuedAt; @@ -31,7 +32,7 @@ class DatetimeClaimTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Validators\PayloadValidator + * @var MockInterface|PayloadValidator */ protected $validator; @@ -109,7 +110,7 @@ public function it_should_handle_datetime_claims() /** @test */ public function it_should_handle_datetime_immutable_claims() { - $testDateTimeImmutable = DateTimeImmutable::createFromFormat('U', (string) $this->testNowTimestamp); + $testDateTimeImmutable = DateTimeImmutable::createFromFormat('U', (string)$this->testNowTimestamp); $this->assertInstanceOf(DateTimeImmutable::class, $testDateTimeImmutable); $this->assertInstanceOf(DatetimeInterface::class, $testDateTimeImmutable); diff --git a/tests/Claims/FactoryTest.php b/tests/Claims/FactoryTest.php index 5d5f001..c4cbade 100644 --- a/tests/Claims/FactoryTest.php +++ b/tests/Claims/FactoryTest.php @@ -26,7 +26,7 @@ class FactoryTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Claims\Factory + * @var Factory */ protected $factory; diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index fa92042..e68e096 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -12,6 +12,7 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Claims\Custom; use PHPOpenSourceSaver\JWTAuth\Claims\Expiration; @@ -28,17 +29,17 @@ class FactoryTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Claims\Factory + * @var MockInterface|ClaimFactory */ protected $claimFactory; /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Validators\PayloadValidator + * @var MockInterface|PayloadValidator */ protected $validator; /** - * @var \PHPOpenSourceSaver\JWTAuth\Factory + * @var Factory */ protected $factory; diff --git a/tests/Http/ParserTest.php b/tests/Http/ParserTest.php index fb12327..d8fcd4c 100644 --- a/tests/Http/ParserTest.php +++ b/tests/Http/ParserTest.php @@ -334,6 +334,15 @@ public function it_should_return_the_token_from_route() $this->assertTrue($parser->hasToken()); } + protected function getRouteMock($expectedParameterValue = null, $expectedParameterName = 'token') + { + return Mockery::mock(Route::class) + ->shouldReceive('parameter') + ->with($expectedParameterName) + ->andReturn($expectedParameterValue) + ->getMock(); + } + /** @test */ public function it_should_return_the_token_from_route_with_a_custom_param() { @@ -460,7 +469,7 @@ public function it_should_retrieve_the_chain_with_alias() new RouteParams, ]; - /* @var \Illuminate\Http\Request $request */ + /* @var Request $request */ $request = Mockery::mock(Request::class); $parser = new Parser($request); @@ -508,13 +517,4 @@ public function it_should_add_multiple_custom_parser() $this->assertSame($parser->parseToken(), 'foobar'); $this->assertTrue($parser->hasToken()); } - - protected function getRouteMock($expectedParameterValue = null, $expectedParameterName = 'token') - { - return Mockery::mock(Route::class) - ->shouldReceive('parameter') - ->with($expectedParameterName) - ->andReturn($expectedParameterValue) - ->getMock(); - } } diff --git a/tests/JWTAuthTest.php b/tests/JWTAuthTest.php index 7548a2a..2683d2c 100644 --- a/tests/JWTAuthTest.php +++ b/tests/JWTAuthTest.php @@ -13,7 +13,7 @@ use Illuminate\Http\Request; use Mockery; -use stdClass; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Contracts\Providers\Auth; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; @@ -24,26 +24,27 @@ use PHPOpenSourceSaver\JWTAuth\Payload; use PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub; use PHPOpenSourceSaver\JWTAuth\Token; +use stdClass; class JWTAuthTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Manager + * @var MockInterface|Manager */ protected $manager; /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Contracts\Providers\Auth + * @var MockInterface|Auth */ protected $auth; /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser + * @var MockInterface|Parser */ protected $parser; /** - * @var \PHPOpenSourceSaver\JWTAuth\JWTAuth + * @var JWTAuth */ protected $jwtAuth; @@ -62,10 +63,10 @@ public function it_should_return_a_token_when_passing_a_user() $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); $this->manager - ->shouldReceive('getPayloadFactory->customClaims') - ->once() - ->with(['sub' => 1, 'prv' => sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub'), 'foo' => 'bar', 'role' => 'admin']) - ->andReturn($payloadFactory); + ->shouldReceive('getPayloadFactory->customClaims') + ->once() + ->with(['sub' => 1, 'prv' => sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub'), 'foo' => 'bar', 'role' => 'admin']) + ->andReturn($payloadFactory); $this->manager->shouldReceive('encode->get')->once()->andReturn('foo.bar.baz'); @@ -80,8 +81,8 @@ public function it_should_pass_provider_check_if_hash_matches() $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')); + ->with('prv') + ->andReturn(sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub')); $this->manager->shouldReceive('decode')->once()->andReturn($payloadFactory); @@ -94,8 +95,8 @@ public function it_should_pass_provider_check_if_hash_matches_when_provider_is_n $payloadFactory = Mockery::mock(Factory::class); $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); $payloadFactory->shouldReceive('get') - ->with('prv') - ->andReturnNull(); + ->with('prv') + ->andReturnNull(); $this->manager->shouldReceive('decode')->once()->andReturn($payloadFactory); @@ -108,8 +109,8 @@ public function it_should_not_pass_provider_check_if_hash_not_match() $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')); + ->with('prv') + ->andReturn(sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub1')); $this->manager->shouldReceive('decode')->once()->andReturn($payloadFactory); @@ -123,10 +124,10 @@ public function it_should_return_a_token_when_passing_valid_credentials_to_attem $payloadFactory->shouldReceive('make')->andReturn(Mockery::mock(Payload::class)); $this->manager - ->shouldReceive('getPayloadFactory->customClaims') - ->once() - ->with(['sub' => 1, 'prv' => sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub'), 'foo' => 'bar', 'role' => 'admin']) - ->andReturn($payloadFactory); + ->shouldReceive('getPayloadFactory->customClaims') + ->once() + ->with(['sub' => 1, 'prv' => sha1('PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub'), 'foo' => 'bar', 'role' => 'admin']) + ->andReturn($payloadFactory); $this->manager->shouldReceive('encode->get')->once()->andReturn('foo.bar.baz'); @@ -168,7 +169,7 @@ public function it_should_return_the_owning_user_from_a_token_containing_an_exis $this->manager->shouldReceive('decode')->once()->andReturn($payload); $this->auth->shouldReceive('byId')->once()->with(1)->andReturn(true); - $this->auth->shouldReceive('user')->once()->andReturn((object) ['id' => 1]); + $this->auth->shouldReceive('user')->once()->andReturn((object)['id' => 1]); $user = $this->jwtAuth->setToken('foo.bar.baz')->customClaims(['foo' => 'bar'])->authenticate(); diff --git a/tests/JWTGuardTest.php b/tests/JWTGuardTest.php index 4b9aa91..f6e571c 100644 --- a/tests/JWTGuardTest.php +++ b/tests/JWTGuardTest.php @@ -12,8 +12,10 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; use Illuminate\Auth\EloquentUserProvider; +use Illuminate\Contracts\Auth\UserProvider; use Illuminate\Http\Request; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\UserNotDefinedException; use PHPOpenSourceSaver\JWTAuth\Factory; @@ -25,17 +27,17 @@ class JWTGuardTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\JWT|\Mockery\MockInterface + * @var JWT|MockInterface */ protected $jwt; /** - * @var \Illuminate\Contracts\Auth\UserProvider|\Mockery\MockInterface + * @var UserProvider|MockInterface */ protected $provider; /** - * @var \PHPOpenSourceSaver\JWTAuth\JWTGuard|\Mockery\MockInterface + * @var JWTGuard|MockInterface */ protected $guard; @@ -64,17 +66,17 @@ public function it_should_get_the_authenticated_user_if_a_valid_token_is_provide $this->jwt->shouldReceive('getToken')->once()->andReturn('foo.bar.baz'); $this->jwt->shouldReceive('check')->once()->with(true)->andReturn($payload); $this->jwt->shouldReceive('checkSubjectModel') - ->once() - ->with('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub') - ->andReturn(true); + ->once() + ->with('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub') + ->andReturn(true); $this->provider->shouldReceive('getModel') - ->once() - ->andReturn('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub'); + ->once() + ->andReturn('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub'); $this->provider->shouldReceive('retrieveById') - ->once() - ->with(1) - ->andReturn((object) ['id' => 1]); + ->once() + ->with(1) + ->andReturn((object)['id' => 1]); $this->assertSame(1, $this->guard->user()->id); @@ -96,17 +98,17 @@ public function it_should_get_the_authenticated_user_if_a_valid_token_is_provide $this->jwt->shouldReceive('getToken')->once()->andReturn('foo.bar.baz'); $this->jwt->shouldReceive('check')->once()->with(true)->andReturn($payload); $this->jwt->shouldReceive('checkSubjectModel') - ->once() - ->with('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub') - ->andReturn(true); + ->once() + ->with('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub') + ->andReturn(true); $this->provider->shouldReceive('getModel') - ->once() - ->andReturn('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub'); + ->once() + ->andReturn('\PHPOpenSourceSaver\JWTAuth\Test\Stubs\LaravelUserStub'); $this->provider->shouldReceive('retrieveById') - ->once() - ->with(1) - ->andReturn((object) ['id' => 1]); + ->once() + ->with(1) + ->andReturn((object)['id' => 1]); $this->assertSame(1, $this->guard->userOrFail()->id); @@ -180,29 +182,29 @@ public function it_should_return_a_token_if_credentials_are_ok_and_user_is_found $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveByCredentials') - ->once() - ->with($credentials) - ->andReturn($user); + ->once() + ->with($credentials) + ->andReturn($user); $this->provider->shouldReceive('validateCredentials') - ->once() - ->with($user, $credentials) - ->andReturn(true); + ->once() + ->with($user, $credentials) + ->andReturn(true); $this->jwt->shouldReceive('fromUser') - ->once() - ->with($user) - ->andReturn('foo.bar.baz'); + ->once() + ->with($user) + ->andReturn('foo.bar.baz'); $this->jwt->shouldReceive('setToken') - ->once() - ->with('foo.bar.baz') - ->andReturnSelf(); + ->once() + ->with('foo.bar.baz') + ->andReturnSelf(); $this->jwt->shouldReceive('claims') - ->once() - ->with(['foo' => 'bar']) - ->andReturnSelf(); + ->once() + ->with(['foo' => 'bar']) + ->andReturnSelf(); $token = $this->guard->claims(['foo' => 'bar'])->attempt($credentials); @@ -217,14 +219,14 @@ public function it_should_return_true_if_credentials_are_ok_and_user_is_found_wh $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveByCredentials') - ->twice() - ->with($credentials) - ->andReturn($user); + ->twice() + ->with($credentials) + ->andReturn($user); $this->provider->shouldReceive('validateCredentials') - ->twice() - ->with($user, $credentials) - ->andReturn(true); + ->twice() + ->with($user, $credentials) + ->andReturn(true); $this->assertTrue($this->guard->attempt($credentials, false)); // once $this->assertTrue($this->guard->validate($credentials)); // twice @@ -237,14 +239,14 @@ public function it_should_return_false_if_credentials_are_invalid() $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveByCredentials') - ->once() - ->with($credentials) - ->andReturn($user); + ->once() + ->with($credentials) + ->andReturn($user); $this->provider->shouldReceive('validateCredentials') - ->once() - ->with($user, $credentials) - ->andReturn(false); + ->once() + ->with($user, $credentials) + ->andReturn(false); $this->assertFalse($this->guard->attempt($credentials)); } @@ -307,14 +309,14 @@ public function it_should_generate_a_token_by_id() $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveById') - ->once() - ->with(1) - ->andReturn($user); + ->once() + ->with(1) + ->andReturn($user); $this->jwt->shouldReceive('fromUser') - ->once() - ->with($user) - ->andReturn('foo.bar.baz'); + ->once() + ->with($user) + ->andReturn('foo.bar.baz'); $this->assertSame('foo.bar.baz', $this->guard->tokenById(1)); } @@ -323,9 +325,9 @@ public function it_should_generate_a_token_by_id() public function it_should_not_generate_a_token_by_id() { $this->provider->shouldReceive('retrieveById') - ->once() - ->with(1) - ->andReturn(null); + ->once() + ->with(1) + ->andReturn(null); $this->assertNull($this->guard->tokenById(1)); } @@ -337,14 +339,14 @@ public function it_should_authenticate_the_user_by_credentials_and_return_true_i $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveByCredentials') - ->once() - ->with($credentials) - ->andReturn($user); + ->once() + ->with($credentials) + ->andReturn($user); $this->provider->shouldReceive('validateCredentials') - ->once() - ->with($user, $credentials) - ->andReturn(true); + ->once() + ->with($user, $credentials) + ->andReturn(true); $this->assertTrue($this->guard->once($credentials)); } @@ -356,14 +358,14 @@ public function it_should_attempt_to_authenticate_the_user_by_credentials_and_re $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveByCredentials') - ->once() - ->with($credentials) - ->andReturn($user); + ->once() + ->with($credentials) + ->andReturn($user); $this->provider->shouldReceive('validateCredentials') - ->once() - ->with($user, $credentials) - ->andReturn(false); + ->once() + ->with($user, $credentials) + ->andReturn(false); $this->assertFalse($this->guard->once($credentials)); } @@ -374,9 +376,9 @@ public function it_should_authenticate_the_user_by_id_and_return_boolean() $user = new LaravelUserStub; $this->provider->shouldReceive('retrieveById') - ->twice() - ->with(1) - ->andReturn($user); + ->twice() + ->with(1) + ->andReturn($user); $this->assertTrue($this->guard->onceUsingId(1)); // once $this->assertTrue($this->guard->byId(1)); // twice @@ -386,9 +388,9 @@ public function it_should_authenticate_the_user_by_id_and_return_boolean() public function it_should_not_authenticate_the_user_by_id_and_return_false() { $this->provider->shouldReceive('retrieveById') - ->twice() - ->with(1) - ->andReturn(null); + ->twice() + ->with(1) + ->andReturn(null); $this->assertFalse($this->guard->onceUsingId(1)); // once $this->assertFalse($this->guard->byId(1)); // twice @@ -400,14 +402,14 @@ public function it_should_create_a_token_from_a_user_object() $user = new LaravelUserStub; $this->jwt->shouldReceive('fromUser') - ->once() - ->with($user) - ->andReturn('foo.bar.baz'); + ->once() + ->with($user) + ->andReturn('foo.bar.baz'); $this->jwt->shouldReceive('setToken') - ->once() - ->with('foo.bar.baz') - ->andReturnSelf(); + ->once() + ->with('foo.bar.baz') + ->andReturnSelf(); $token = $this->guard->login($user); diff --git a/tests/ManagerTest.php b/tests/ManagerTest.php index b888ca4..1c3ddb6 100644 --- a/tests/ManagerTest.php +++ b/tests/ManagerTest.php @@ -12,6 +12,7 @@ namespace PHPOpenSourceSaver\JWTAuth\Test; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Blacklist; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; use PHPOpenSourceSaver\JWTAuth\Claims\Expiration; @@ -32,27 +33,27 @@ class ManagerTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Contracts\Providers\JWT + * @var MockInterface|JWT */ protected $jwt; /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Blacklist + * @var MockInterface|Blacklist */ protected $blacklist; /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Factory + * @var MockInterface|Factory */ protected $factory; /** - * @var \PHPOpenSourceSaver\JWTAuth\Manager + * @var Manager */ protected $manager; /** - * @var \Mockery\MockInterface + * @var MockInterface */ protected $validator; diff --git a/tests/Middleware/AbstractMiddlewareTest.php b/tests/Middleware/AbstractMiddlewareTest.php index 54704b4..7391e4c 100644 --- a/tests/Middleware/AbstractMiddlewareTest.php +++ b/tests/Middleware/AbstractMiddlewareTest.php @@ -13,18 +13,19 @@ use Illuminate\Http\Request; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\JWTAuth; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; abstract class AbstractMiddlewareTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\JWTAuth + * @var MockInterface|JWTAuth */ protected $auth; /** - * @var \Mockery\MockInterface|\Illuminate\Http\Request + * @var MockInterface|Request */ protected $request; diff --git a/tests/Middleware/AuthenticateAndRenewTest.php b/tests/Middleware/AuthenticateAndRenewTest.php index 9b2ba7d..89f959d 100644 --- a/tests/Middleware/AuthenticateAndRenewTest.php +++ b/tests/Middleware/AuthenticateAndRenewTest.php @@ -13,16 +13,17 @@ use Illuminate\Http\Response; use Mockery; -use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; +use PHPOpenSourceSaver\JWTAuth\Http\Middleware\Authenticate; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\AuthenticateAndRenew; use PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser; use PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class AuthenticateAndRenewTest extends AbstractMiddlewareTest { /** - * @var \PHPOpenSourceSaver\JWTAuth\Http\Middleware\Authenticate|\PHPOpenSourceSaver\JWTAuth\Http\Middleware\AuthenticateAndRenew + * @var Authenticate|AuthenticateAndRenew */ protected $middleware; diff --git a/tests/Middleware/AuthenticateTest.php b/tests/Middleware/AuthenticateTest.php index d942f0b..c885e7f 100644 --- a/tests/Middleware/AuthenticateTest.php +++ b/tests/Middleware/AuthenticateTest.php @@ -12,16 +12,16 @@ namespace PHPOpenSourceSaver\JWTAuth\Test\Middleware; use Mockery; -use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\Authenticate; use PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser; use PHPOpenSourceSaver\JWTAuth\Test\Stubs\UserStub; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class AuthenticateTest extends AbstractMiddlewareTest { /** - * @var \PHPOpenSourceSaver\JWTAuth\Http\Middleware\Authenticate + * @var Authenticate */ protected $middleware; diff --git a/tests/Middleware/CheckTest.php b/tests/Middleware/CheckTest.php index 929629a..74074a1 100644 --- a/tests/Middleware/CheckTest.php +++ b/tests/Middleware/CheckTest.php @@ -20,7 +20,7 @@ class CheckTest extends AbstractMiddlewareTest { /** - * @var \PHPOpenSourceSaver\JWTAuth\Http\Middleware\Check + * @var Check */ protected $middleware; diff --git a/tests/Middleware/RefreshTokenTest.php b/tests/Middleware/RefreshTokenTest.php index edc3d16..a5a114a 100644 --- a/tests/Middleware/RefreshTokenTest.php +++ b/tests/Middleware/RefreshTokenTest.php @@ -13,15 +13,15 @@ use Illuminate\Http\Response; use Mockery; -use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Http\Middleware\RefreshToken; use PHPOpenSourceSaver\JWTAuth\Http\Parser\Parser; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class RefreshTokenTest extends AbstractMiddlewareTest { /** - * @var \PHPOpenSourceSaver\JWTAuth\Http\Middleware\RefreshToken + * @var RefreshToken */ protected $middleware; diff --git a/tests/PayloadTest.php b/tests/PayloadTest.php index 48e9584..2dc735a 100644 --- a/tests/PayloadTest.php +++ b/tests/PayloadTest.php @@ -13,6 +13,7 @@ use BadMethodCallException; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Claims\Audience; use PHPOpenSourceSaver\JWTAuth\Claims\Claim; use PHPOpenSourceSaver\JWTAuth\Claims\Collection; @@ -29,12 +30,12 @@ class PayloadTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\PHPOpenSourceSaver\JWTAuth\Validators\PayloadValidator + * @var MockInterface|PayloadValidator */ protected $validator; /** - * @var \PHPOpenSourceSaver\JWTAuth\Payload + * @var Payload */ protected $payload; @@ -46,9 +47,9 @@ public function setUp(): void } /** - * @param array $extraClaims + * @param array $extraClaims * - * @return \PHPOpenSourceSaver\JWTAuth\Payload + * @return Payload */ private function getTestPayload(array $extraClaims = []) { @@ -94,8 +95,8 @@ public function it_should_throw_an_exception_when_trying_to_remove_a_key_from_th /** @test */ public function it_should_cast_the_payload_to_a_string_as_json() { - $this->assertSame((string) $this->payload, json_encode($this->payload->get(), JSON_UNESCAPED_SLASHES)); - $this->assertJsonStringEqualsJsonString((string) $this->payload, json_encode($this->payload->get())); + $this->assertSame((string)$this->payload, json_encode($this->payload->get(), JSON_UNESCAPED_SLASHES)); + $this->assertJsonStringEqualsJsonString((string)$this->payload, json_encode($this->payload->get())); } /** @test */ @@ -206,7 +207,7 @@ public function it_should_count_the_claims() public function it_should_match_values() { $values = $this->payload->toArray(); - $values['sub'] = (string) $values['sub']; + $values['sub'] = (string)$values['sub']; $this->assertTrue($this->payload->matches($values)); } @@ -239,7 +240,7 @@ public function it_should_not_match_values() public function it_should_not_match_strict_values() { $values = $this->payload->toArray(); - $values['sub'] = (string) $values['sub']; + $values['sub'] = (string)$values['sub']; $this->assertFalse($this->payload->matchesStrict($values)); $this->assertFalse($this->payload->matches($values, true)); diff --git a/tests/Providers/Auth/IlluminateTest.php b/tests/Providers/Auth/IlluminateTest.php index 94bca15..7178385 100644 --- a/tests/Providers/Auth/IlluminateTest.php +++ b/tests/Providers/Auth/IlluminateTest.php @@ -13,18 +13,19 @@ use Illuminate\Contracts\Auth\Guard; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Providers\Auth\Illuminate as Auth; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; class IlluminateTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\Illuminate\Contracts\Auth\Guard + * @var MockInterface|Guard */ protected $authManager; /** - * @var \PHPOpenSourceSaver\JWTAuth\Providers\Auth\Illuminate + * @var Auth */ protected $auth; @@ -60,7 +61,7 @@ public function it_should_return_false_if_user_is_not_found() /** @test */ public function it_should_return_the_currently_authenticated_user() { - $this->authManager->shouldReceive('user')->once()->andReturn((object) ['id' => 1]); + $this->authManager->shouldReceive('user')->once()->andReturn((object)['id' => 1]); $this->assertSame($this->auth->user()->id, 1); } } diff --git a/tests/Providers/JWT/LcobucciTest.php b/tests/Providers/JWT/LcobucciTest.php index dd4ac3b..8e8554a 100644 --- a/tests/Providers/JWT/LcobucciTest.php +++ b/tests/Providers/JWT/LcobucciTest.php @@ -17,25 +17,27 @@ use Lcobucci\JWT\Parser; use Lcobucci\JWT\Signer\Key; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; use PHPOpenSourceSaver\JWTAuth\Providers\JWT\Lcobucci; +use PHPOpenSourceSaver\JWTAuth\Providers\JWT\Namshi; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; class LcobucciTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface + * @var MockInterface */ protected $parser; /** - * @var \Mockery\MockInterface + * @var MockInterface */ protected $builder; /** - * @var \PHPOpenSourceSaver\JWTAuth\Providers\JWT\Namshi + * @var Namshi */ protected $provider; @@ -62,6 +64,11 @@ public function it_should_return_the_token_when_passing_a_valid_payload_to_encod $this->assertSame('foo.bar.baz', $token); } + public function getProvider($secret, $algo, array $keys = []) + { + return new Lcobucci($this->builder, $this->parser, $secret, $algo, $keys); + } + /** @test */ public function it_should_throw_an_invalid_exception_when_the_payload_could_not_be_encoded() { @@ -136,6 +143,16 @@ public function it_should_generate_a_token_when_using_an_rsa_algorithm() $this->assertSame('foo.bar.baz', $token); } + public function getDummyPrivateKey() + { + return file_get_contents(__DIR__ . '/../Keys/id_rsa'); + } + + public function getDummyPublicKey() + { + return file_get_contents(__DIR__ . '/../Keys/id_rsa.pub'); + } + /** @test */ public function it_should_throw_a_exception_when_the_algorithm_passed_is_invalid() { @@ -171,19 +188,4 @@ public function it_should_return_the_keys() $this->assertSame($keys, $provider->getKeys()); } - - public function getProvider($secret, $algo, array $keys = []) - { - return new Lcobucci($this->builder, $this->parser, $secret, $algo, $keys); - } - - public function getDummyPrivateKey() - { - return file_get_contents(__DIR__.'/../Keys/id_rsa'); - } - - public function getDummyPublicKey() - { - return file_get_contents(__DIR__.'/../Keys/id_rsa.pub'); - } } diff --git a/tests/Providers/JWT/NamshiTest.php b/tests/Providers/JWT/NamshiTest.php index 3f3e448..375b8f9 100644 --- a/tests/Providers/JWT/NamshiTest.php +++ b/tests/Providers/JWT/NamshiTest.php @@ -14,6 +14,7 @@ use Exception; use InvalidArgumentException; use Mockery; +use Mockery\MockInterface; use Namshi\JOSE\JWS; use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException; use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException; @@ -23,12 +24,12 @@ class NamshiTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface + * @var MockInterface */ protected $jws; /** - * @var \PHPOpenSourceSaver\JWTAuth\Providers\JWT\Namshi + * @var Namshi */ protected $provider; @@ -53,6 +54,11 @@ public function it_should_return_the_token_when_passing_a_valid_payload_to_encod $this->assertSame('foo.bar.baz', $token); } + public function getProvider($secret, $algo, array $keys = []) + { + return new Namshi($this->jws, $secret, $algo, $keys); + } + /** @test */ public function it_should_throw_an_invalid_exception_when_the_payload_could_not_be_encoded() { @@ -125,6 +131,16 @@ public function it_should_generate_a_token_when_using_an_rsa_algorithm() $this->assertSame('foo.bar.baz', $token); } + public function getDummyPrivateKey() + { + return file_get_contents(__DIR__ . '/../Keys/id_rsa'); + } + + public function getDummyPublicKey() + { + return file_get_contents(__DIR__ . '/../Keys/id_rsa.pub'); + } + /** @test */ public function it_should_generate_a_token_when_using_an_ecdsa_algorithm() { @@ -200,19 +216,4 @@ public function it_should_return_the_keys() $this->assertSame($keys, $provider->getKeys()); } - - public function getProvider($secret, $algo, array $keys = []) - { - return new Namshi($this->jws, $secret, $algo, $keys); - } - - public function getDummyPrivateKey() - { - return file_get_contents(__DIR__.'/../Keys/id_rsa'); - } - - public function getDummyPublicKey() - { - return file_get_contents(__DIR__.'/../Keys/id_rsa.pub'); - } } diff --git a/tests/Providers/JWT/ProviderTest.php b/tests/Providers/JWT/ProviderTest.php index f921ce9..41fb181 100644 --- a/tests/Providers/JWT/ProviderTest.php +++ b/tests/Providers/JWT/ProviderTest.php @@ -17,7 +17,7 @@ class ProviderTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Test\Stubs\JWTProviderStub + * @var JWTProviderStub */ protected $provider; diff --git a/tests/Providers/Storage/IlluminateTest.php b/tests/Providers/Storage/IlluminateTest.php index 1974ed1..a336947 100644 --- a/tests/Providers/Storage/IlluminateTest.php +++ b/tests/Providers/Storage/IlluminateTest.php @@ -13,6 +13,7 @@ use Illuminate\Contracts\Cache\Repository; use Mockery; +use Mockery\MockInterface; use PHPOpenSourceSaver\JWTAuth\Providers\Storage\Illuminate as Storage; use PHPOpenSourceSaver\JWTAuth\Test\AbstractTestCase; use PHPOpenSourceSaver\JWTAuth\Test\Stubs\TaggedStorage; @@ -20,12 +21,12 @@ class IlluminateTest extends AbstractTestCase { /** - * @var \Mockery\MockInterface|\Illuminate\Contracts\Cache\Repository + * @var MockInterface|Repository */ protected $cache; /** - * @var \PHPOpenSourceSaver\JWTAuth\Providers\Storage\Illuminate + * @var Storage */ protected $storage; @@ -79,6 +80,15 @@ public function it_should_remove_all_items_from_storage() // Duplicate tests for tagged storage -------------------- + /** @test */ + public function it_should_add_the_item_to_tagged_storage() + { + $this->emulateTags(); + $this->cache->shouldReceive('put')->with('foo', 'bar', 10)->once(); + + $this->storage->add('foo', 'bar', 10); + } + /** * Replace the storage with our one above that overrides the tag flag, and * define expectations for tags() method. @@ -92,15 +102,6 @@ private function emulateTags() $this->cache->shouldReceive('tags')->with('tymon.jwt')->once()->andReturn(Mockery::self()); } - /** @test */ - public function it_should_add_the_item_to_tagged_storage() - { - $this->emulateTags(); - $this->cache->shouldReceive('put')->with('foo', 'bar', 10)->once(); - - $this->storage->add('foo', 'bar', 10); - } - /** @test */ public function it_should_add_the_item_to_tagged_storage_forever() { diff --git a/tests/TokenTest.php b/tests/TokenTest.php index bdecacb..3616c2a 100644 --- a/tests/TokenTest.php +++ b/tests/TokenTest.php @@ -16,7 +16,7 @@ class TokenTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Token + * @var Token */ protected $token; @@ -30,7 +30,7 @@ public function setUp(): void /** @test */ public function it_should_return_the_token_when_casting_to_a_string() { - $this->assertEquals((string) $this->token, $this->token); + $this->assertEquals((string)$this->token, $this->token); } /** @test */ diff --git a/tests/Validators/PayloadValidatorTest.php b/tests/Validators/PayloadValidatorTest.php index 9941143..b9a8d33 100644 --- a/tests/Validators/PayloadValidatorTest.php +++ b/tests/Validators/PayloadValidatorTest.php @@ -27,7 +27,7 @@ class PayloadValidatorTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Validators\PayloadValidator + * @var PayloadValidator */ protected $validator; diff --git a/tests/Validators/TokenValidatorTest.php b/tests/Validators/TokenValidatorTest.php index 98de51a..2304206 100644 --- a/tests/Validators/TokenValidatorTest.php +++ b/tests/Validators/TokenValidatorTest.php @@ -18,7 +18,7 @@ class TokenValidatorTest extends AbstractTestCase { /** - * @var \PHPOpenSourceSaver\JWTAuth\Validators\TokenValidator + * @var TokenValidator */ protected $validator; @@ -39,7 +39,7 @@ public function it_should_return_true_when_providing_a_well_formed_token() * @test * @dataProvider \PHPOpenSourceSaver\JWTAuth\Test\Validators\TokenValidatorTest::dataProviderMalformedTokens * - * @param string $token + * @param string $token */ public function it_should_return_false_when_providing_a_malformed_token($token) {