Skip to content

Commit

Permalink
[10.x] Support Laravel 8 (#1336)
Browse files Browse the repository at this point in the history
* Support Laravel 8

* Fix factories

* Apply fixes from StyleCI (#1337)

* fix tests

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
driesvints and taylorotwell authored Aug 25, 2020
1 parent 8b41a82 commit df21a43
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
27 changes: 14 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@
}
],
"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",
"symfony/psr-http-message-bridge": "^2.0"
},
"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": {
Expand Down
48 changes: 48 additions & 0 deletions database/factories/ClientFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Laravel\Passport\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Laravel\Passport\Client;

class ClientFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Client::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'user_id' => 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,
]);
}
}
26 changes: 0 additions & 26 deletions database/factories/PassportClientFactory.php

This file was deleted.

14 changes: 7 additions & 7 deletions tests/Feature/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

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;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Database\Factories\ClientFactory;
use Laravel\Passport\HasApiTokens;
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
Expand Down Expand Up @@ -52,7 +52,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 = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);

$response = $this->post(
'/oauth/token',
Expand All @@ -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);
Expand Down Expand Up @@ -103,7 +103,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 = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);

$response = $this->post(
'/oauth/token',
Expand All @@ -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);
Expand All @@ -146,7 +146,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 = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);

$response = $this->post(
'/oauth/token',
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/PassportTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ protected function setUp(): void
{
parent::setUp();

$this->withFactories(__DIR__.'/../../database/factories');

$this->artisan('migrate:fresh');

Passport::routes();
Expand Down

0 comments on commit df21a43

Please sign in to comment.