Skip to content

Commit df21a43

Browse files
[10.x] Support Laravel 8 (#1336)
* Support Laravel 8 * Fix factories * Apply fixes from StyleCI (#1337) * fix tests Co-authored-by: Taylor Otwell <[email protected]>
1 parent 8b41a82 commit df21a43

File tree

6 files changed

+71
-50
lines changed

6 files changed

+71
-50
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [7.2, 7.3, 7.4]
17-
laravel: [^6.0, ^7.0]
16+
php: [7.3, 7.4]
17+
laravel: [^8.0]
1818

1919
name: P${{ matrix.php }} - L${{ matrix.laravel }}
2020

composer.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,32 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.2",
17+
"php": "^7.3",
1818
"ext-json": "*",
1919
"firebase/php-jwt": "^5.0",
20-
"illuminate/auth": "^6.18.31|^7.22.4",
21-
"illuminate/console": "^6.18.31|^7.22.4",
22-
"illuminate/container": "^6.18.31|^7.22.4",
23-
"illuminate/contracts": "^6.18.31|^7.22.4",
24-
"illuminate/cookie": "^6.18.31|^7.22.4",
25-
"illuminate/database": "^6.18.31|^7.22.4",
26-
"illuminate/encryption": "^6.18.31|^7.22.4",
27-
"illuminate/http": "^6.18.31|^7.22.4",
28-
"illuminate/support": "^6.18.31|^7.22.4",
20+
"illuminate/auth": "^8.0",
21+
"illuminate/console": "^8.0",
22+
"illuminate/container": "^8.0",
23+
"illuminate/contracts": "^8.0",
24+
"illuminate/cookie": "^8.0",
25+
"illuminate/database": "^8.0",
26+
"illuminate/encryption": "^8.0",
27+
"illuminate/http": "^8.0",
28+
"illuminate/support": "^8.0",
2929
"league/oauth2-server": "^8.1",
3030
"nyholm/psr7": "^1.3",
3131
"phpseclib/phpseclib": "^2.0",
3232
"symfony/psr-http-message-bridge": "^2.0"
3333
},
3434
"require-dev": {
3535
"mockery/mockery": "^1.0",
36-
"orchestra/testbench": "^4.4|^5.0",
37-
"phpunit/phpunit": "^8.5|^9.3"
36+
"orchestra/testbench": "^6.0",
37+
"phpunit/phpunit": "^9.3"
3838
},
3939
"autoload": {
4040
"psr-4": {
41-
"Laravel\\Passport\\": "src/"
41+
"Laravel\\Passport\\": "src/",
42+
"Laravel\\Passport\\Database\\Factories\\": "database/factories/"
4243
}
4344
},
4445
"autoload-dev": {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Laravel\Passport\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Support\Str;
7+
use Laravel\Passport\Client;
8+
9+
class ClientFactory extends Factory
10+
{
11+
/**
12+
* The name of the factory's corresponding model.
13+
*
14+
* @var string
15+
*/
16+
protected $model = Client::class;
17+
18+
/**
19+
* Define the model's default state.
20+
*
21+
* @return array
22+
*/
23+
public function definition()
24+
{
25+
return [
26+
'user_id' => null,
27+
'name' => $this->faker->company,
28+
'secret' => Str::random(40),
29+
'redirect' => $this->faker->url,
30+
'personal_access_client' => false,
31+
'password_client' => false,
32+
'revoked' => false,
33+
];
34+
}
35+
36+
/**
37+
* Use as Password Client.
38+
*
39+
* @return $this
40+
*/
41+
public function asPasswordClient()
42+
{
43+
return $this->state([
44+
'personal_access_client' => false,
45+
'password_client' => true,
46+
]);
47+
}
48+
}

database/factories/PassportClientFactory.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/Feature/AccessTokenControllerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use Carbon\CarbonImmutable;
66
use Illuminate\Contracts\Hashing\Hasher;
7-
use Illuminate\Database\Eloquent\Factory;
87
use Illuminate\Database\Schema\Blueprint;
98
use Illuminate\Support\Facades\Schema;
109
use Laravel\Passport\Client;
1110
use Laravel\Passport\ClientRepository;
11+
use Laravel\Passport\Database\Factories\ClientFactory;
1212
use Laravel\Passport\HasApiTokens;
1313
use Laravel\Passport\Token;
1414
use Laravel\Passport\TokenRepository;
@@ -52,7 +52,7 @@ public function testGettingAccessTokenWithPasswordGrant()
5252
$user->save();
5353

5454
/** @var Client $client */
55-
$client = $this->app->make(Factory::class)->of(Client::class)->state('password_client')->create(['user_id' => $user->id]);
55+
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);
5656

5757
$response = $this->post(
5858
'/oauth/token',
@@ -71,7 +71,7 @@ public function testGettingAccessTokenWithPasswordGrant()
7171
$response->assertHeader('cache-control', 'no-store, private');
7272
$response->assertHeader('content-type', 'application/json; charset=UTF-8');
7373

74-
$decodedResponse = $response->decodeResponseJson();
74+
$decodedResponse = $response->decodeResponseJson()->json();
7575

7676
$this->assertArrayHasKey('token_type', $decodedResponse);
7777
$this->assertArrayHasKey('expires_in', $decodedResponse);
@@ -103,7 +103,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
103103
$user->save();
104104

105105
/** @var Client $client */
106-
$client = $this->app->make(Factory::class)->of(Client::class)->state('password_client')->create(['user_id' => $user->id]);
106+
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);
107107

108108
$response = $this->post(
109109
'/oauth/token',
@@ -121,7 +121,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
121121
$response->assertHeader('cache-control', 'no-cache, private');
122122
$response->assertHeader('content-type', 'application/json');
123123

124-
$decodedResponse = $response->decodeResponseJson();
124+
$decodedResponse = $response->decodeResponseJson()->json();
125125

126126
$this->assertArrayNotHasKey('token_type', $decodedResponse);
127127
$this->assertArrayNotHasKey('expires_in', $decodedResponse);
@@ -146,7 +146,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
146146
$user->save();
147147

148148
/** @var Client $client */
149-
$client = $this->app->make(Factory::class)->of(Client::class)->state('password_client')->create(['user_id' => $user->id]);
149+
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);
150150

151151
$response = $this->post(
152152
'/oauth/token',
@@ -164,7 +164,7 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
164164
$response->assertHeader('cache-control', 'no-cache, private');
165165
$response->assertHeader('content-type', 'application/json');
166166

167-
$decodedResponse = $response->decodeResponseJson();
167+
$decodedResponse = $response->decodeResponseJson()->json();
168168

169169
$this->assertArrayNotHasKey('token_type', $decodedResponse);
170170
$this->assertArrayNotHasKey('expires_in', $decodedResponse);

tests/Feature/PassportTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ protected function setUp(): void
2020
{
2121
parent::setUp();
2222

23-
$this->withFactories(__DIR__.'/../../database/factories');
24-
2523
$this->artisan('migrate:fresh');
2624

2725
Passport::routes();

0 commit comments

Comments
 (0)