From 421b38aff9eb34e2342179992558cdb603db3e09 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 25 Aug 2020 19:20:38 +0200 Subject: [PATCH 1/4] Support Laravel 8 --- .github/workflows/tests.yml | 4 +- composer.json | 27 +++++------ database/factories/ClientFactory.php | 49 ++++++++++++++++++++ database/factories/PassportClientFactory.php | 26 ----------- tests/Feature/AccessTokenControllerTest.php | 7 ++- 5 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 database/factories/ClientFactory.php delete mode 100644 database/factories/PassportClientFactory.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36ef2a9d2..7acc16c95 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,8 +13,8 @@ jobs: strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4] - laravel: [^6.0, ^7.0] + php: [7.3, 7.4] + laravel: [^8.0] name: P${{ matrix.php }} - L${{ matrix.laravel }} diff --git a/composer.json b/composer.json index f1f910850..9d3d1cde7 100644 --- a/composer.json +++ b/composer.json @@ -14,18 +14,18 @@ } ], "require": { - "php": "^7.2", + "php": "^7.3", "ext-json": "*", "firebase/php-jwt": "^5.0", - "illuminate/auth": "^6.18.31|^7.22.4", - "illuminate/console": "^6.18.31|^7.22.4", - "illuminate/container": "^6.18.31|^7.22.4", - "illuminate/contracts": "^6.18.31|^7.22.4", - "illuminate/cookie": "^6.18.31|^7.22.4", - "illuminate/database": "^6.18.31|^7.22.4", - "illuminate/encryption": "^6.18.31|^7.22.4", - "illuminate/http": "^6.18.31|^7.22.4", - "illuminate/support": "^6.18.31|^7.22.4", + "illuminate/auth": "^8.0", + "illuminate/console": "^8.0", + "illuminate/container": "^8.0", + "illuminate/contracts": "^8.0", + "illuminate/cookie": "^8.0", + "illuminate/database": "^8.0", + "illuminate/encryption": "^8.0", + "illuminate/http": "^8.0", + "illuminate/support": "^8.0", "league/oauth2-server": "^8.1", "nyholm/psr7": "^1.3", "phpseclib/phpseclib": "^2.0", @@ -33,12 +33,13 @@ }, "require-dev": { "mockery/mockery": "^1.0", - "orchestra/testbench": "^4.4|^5.0", - "phpunit/phpunit": "^8.5|^9.3" + "orchestra/testbench": "^6.0", + "phpunit/phpunit": "^9.3" }, "autoload": { "psr-4": { - "Laravel\\Passport\\": "src/" + "Laravel\\Passport\\": "src/", + "Laravel\\Passport\\Database\\Factories\\": "database/factories/" } }, "autoload-dev": { diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php new file mode 100644 index 000000000..74193dbce --- /dev/null +++ b/database/factories/ClientFactory.php @@ -0,0 +1,49 @@ + null, + 'name' => $this->faker->company, + 'secret' => Str::random(40), + 'redirect' => $this->faker->url, + 'personal_access_client' => false, + 'password_client' => false, + 'revoked' => false, + ]; + } + + /** + * Use as Password Client. + * + * @return $this + */ + public function asPasswordClient() + { + return $this->state([ + 'personal_access_client' => false, + 'password_client' => true, + ]); + } +} diff --git a/database/factories/PassportClientFactory.php b/database/factories/PassportClientFactory.php deleted file mode 100644 index a84c4c6ab..000000000 --- a/database/factories/PassportClientFactory.php +++ /dev/null @@ -1,26 +0,0 @@ -define(Client::class, function (Faker $faker) { - return [ - 'user_id' => null, - 'name' => $faker->company, - 'secret' => Str::random(40), - 'redirect' => $faker->url, - 'personal_access_client' => false, - 'password_client' => false, - 'revoked' => false, - ]; -}); - -$factory->state(Client::class, 'password_client', function (Faker $faker) { - return [ - 'personal_access_client' => false, - 'password_client' => true, - ]; -}); diff --git a/tests/Feature/AccessTokenControllerTest.php b/tests/Feature/AccessTokenControllerTest.php index 48697da62..1558eca7f 100644 --- a/tests/Feature/AccessTokenControllerTest.php +++ b/tests/Feature/AccessTokenControllerTest.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Illuminate\Contracts\Hashing\Hasher; -use Illuminate\Database\Eloquent\Factory; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Laravel\Passport\Client; @@ -52,7 +51,7 @@ public function testGettingAccessTokenWithPasswordGrant() $user->save(); /** @var Client $client */ - $client = $this->app->make(Factory::class)->of(Client::class)->state('password_client')->create(['user_id' => $user->id]); + $client = Client::factory()->asPasswordClient()->create(['user_id' => $user->id]); $response = $this->post( '/oauth/token', @@ -103,7 +102,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword() $user->save(); /** @var Client $client */ - $client = $this->app->make(Factory::class)->of(Client::class)->state('password_client')->create(['user_id' => $user->id]); + $client = Client::factory()->asPasswordClient()->create(['user_id' => $user->id]); $response = $this->post( '/oauth/token', @@ -146,7 +145,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret() $user->save(); /** @var Client $client */ - $client = $this->app->make(Factory::class)->of(Client::class)->state('password_client')->create(['user_id' => $user->id]); + $client = Client::factory()->asPasswordClient()->create(['user_id' => $user->id]); $response = $this->post( '/oauth/token', From 40956f1841b5a62e6c99dae8efd363e4e5d2eac0 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 25 Aug 2020 19:38:21 +0200 Subject: [PATCH 2/4] Fix factories --- tests/Feature/AccessTokenControllerTest.php | 7 ++++--- tests/Feature/PassportTestCase.php | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Feature/AccessTokenControllerTest.php b/tests/Feature/AccessTokenControllerTest.php index 1558eca7f..b6d7df48c 100644 --- a/tests/Feature/AccessTokenControllerTest.php +++ b/tests/Feature/AccessTokenControllerTest.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Schema; use Laravel\Passport\Client; use Laravel\Passport\ClientRepository; +use Laravel\Passport\Database\Factories\ClientFactory; use Laravel\Passport\HasApiTokens; use Laravel\Passport\Token; use Laravel\Passport\TokenRepository; @@ -51,7 +52,7 @@ public function testGettingAccessTokenWithPasswordGrant() $user->save(); /** @var Client $client */ - $client = Client::factory()->asPasswordClient()->create(['user_id' => $user->id]); + $client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]); $response = $this->post( '/oauth/token', @@ -102,7 +103,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword() $user->save(); /** @var Client $client */ - $client = Client::factory()->asPasswordClient()->create(['user_id' => $user->id]); + $client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]); $response = $this->post( '/oauth/token', @@ -145,7 +146,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret() $user->save(); /** @var Client $client */ - $client = Client::factory()->asPasswordClient()->create(['user_id' => $user->id]); + $client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]); $response = $this->post( '/oauth/token', diff --git a/tests/Feature/PassportTestCase.php b/tests/Feature/PassportTestCase.php index 4e0cded0c..d7da023cb 100644 --- a/tests/Feature/PassportTestCase.php +++ b/tests/Feature/PassportTestCase.php @@ -20,8 +20,6 @@ protected function setUp(): void { parent::setUp(); - $this->withFactories(__DIR__.'/../../database/factories'); - $this->artisan('migrate:fresh'); Passport::routes(); From 62a1ca7d0e8c0e541494b260e6cb514f9ac715a9 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Tue, 25 Aug 2020 19:39:12 +0200 Subject: [PATCH 3/4] Apply fixes from StyleCI (#1337) --- database/factories/ClientFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/database/factories/ClientFactory.php b/database/factories/ClientFactory.php index 74193dbce..e844cafe5 100644 --- a/database/factories/ClientFactory.php +++ b/database/factories/ClientFactory.php @@ -2,7 +2,6 @@ namespace Laravel\Passport\Database\Factories; -use Faker\Generator as Faker; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; use Laravel\Passport\Client; From 4f43ed50b758181a2bb0f8cc40e1ffc48d608716 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 25 Aug 2020 12:41:21 -0500 Subject: [PATCH 4/4] fix tests --- tests/Feature/AccessTokenControllerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Feature/AccessTokenControllerTest.php b/tests/Feature/AccessTokenControllerTest.php index b6d7df48c..98698dd6c 100644 --- a/tests/Feature/AccessTokenControllerTest.php +++ b/tests/Feature/AccessTokenControllerTest.php @@ -71,7 +71,7 @@ public function testGettingAccessTokenWithPasswordGrant() $response->assertHeader('cache-control', 'no-store, private'); $response->assertHeader('content-type', 'application/json; charset=UTF-8'); - $decodedResponse = $response->decodeResponseJson(); + $decodedResponse = $response->decodeResponseJson()->json(); $this->assertArrayHasKey('token_type', $decodedResponse); $this->assertArrayHasKey('expires_in', $decodedResponse); @@ -121,7 +121,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword() $response->assertHeader('cache-control', 'no-cache, private'); $response->assertHeader('content-type', 'application/json'); - $decodedResponse = $response->decodeResponseJson(); + $decodedResponse = $response->decodeResponseJson()->json(); $this->assertArrayNotHasKey('token_type', $decodedResponse); $this->assertArrayNotHasKey('expires_in', $decodedResponse); @@ -164,7 +164,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret() $response->assertHeader('cache-control', 'no-cache, private'); $response->assertHeader('content-type', 'application/json'); - $decodedResponse = $response->decodeResponseJson(); + $decodedResponse = $response->decodeResponseJson()->json(); $this->assertArrayNotHasKey('token_type', $decodedResponse); $this->assertArrayNotHasKey('expires_in', $decodedResponse);