Skip to content

Commit 0a9809e

Browse files
authored
Laravel 10 support (#15)
* Update dependencies and resolve deprecations * Update CI script based on Spatie Skeleton * Update code style to use Laravel Pint
1 parent d48215c commit 0a9809e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+370
-385
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
name: CI
22

3-
on:
3+
on:
44
push:
5-
branches:
6-
- "master"
5+
paths:
6+
- '**.php'
7+
- '.github/workflows/run-tests.yml'
8+
- 'phpunit.xml.dist'
9+
- 'composer.json'
10+
- 'composer.lock'
711
pull_request:
812
types: [opened, synchronize, reopened]
913

1014
jobs:
1115
phpunit:
12-
name: Tests PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
13-
runs-on: ubuntu-latest
16+
name: Tests PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
17+
runs-on: ${{ matrix.os }}
1418

1519
strategy:
1620
fail-fast: true
1721
matrix:
18-
php: [7.3, 7.4, 8.0, 8.1]
19-
laravel: ["8.*", "9.*"]
20-
exclude:
21-
- php: 7.3
22-
laravel: "9.*"
23-
- php: 7.4
24-
laravel: "9.*"
22+
os: [ubuntu-latest, windows-latest]
23+
php: [8.3, 8.4]
24+
laravel: ["10.*"]
25+
stability: [prefer-lowest, prefer-stable]
26+
include:
27+
- laravel: 10.*
28+
testbench: 8.*
29+
carbon: ^2.63
2530

2631
steps:
27-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v4
2833
with:
2934
fetch-depth: 1
3035

3136
- name: Cache dependencies
32-
uses: actions/cache@v1
37+
uses: actions/cache@v4
3338
with:
3439
path: ~/.composer/cache/files
3540
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
@@ -38,12 +43,21 @@ jobs:
3843
uses: shivammathur/setup-php@v2
3944
with:
4045
php-version: ${{ matrix.php }}
41-
extensions: dom, curl, libxml, mbstring, zip
46+
extensions: dom, curl, libxml, mbstring, zip, fileinfo, sqlite, pdo_sqlite
4247
coverage: none
48+
49+
- name: Setup problem matchers
50+
run: |
51+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
52+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
4353
4454
- name: Install dependencies
4555
run: |
46-
composer require "illuminate/support:${{ matrix.laravel }}" --prefer-dist --no-interaction
56+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
57+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
58+
59+
- name: List Installed Dependencies
60+
run: composer show -D
4761

4862
- name: Run Testsuite
4963
run: ./vendor/bin/phpunit

.github/workflows/code-style.yml

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,28 @@
11
name: Code-Style
22

3-
on:
3+
on:
44
push:
5-
branches:
6-
- "master"
7-
pull_request:
8-
types: [opened, synchronize, reopened]
5+
paths:
6+
- '**.php'
7+
8+
permissions:
9+
contents: write
910

1011
jobs:
11-
php-code-style:
12-
name: Check PHP code style
12+
php-code-styling:
1313
runs-on: ubuntu-latest
14+
timeout-minutes: 5
1415

1516
steps:
16-
- uses: actions/checkout@v2
17-
with:
18-
fetch-depth: 1
19-
20-
- name: Cache dependencies
21-
uses: actions/cache@v1
22-
with:
23-
path: ~/.composer/cache/files
24-
key: dependencies-php-code-style-composer-${{ hashFiles('composer.json') }}
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
ref: ${{ github.head_ref }}
2521

26-
- name: Setup PHP
27-
uses: shivammathur/setup-php@v2
28-
with:
29-
php-version: 8.0
30-
tools: composer:v2
31-
extensions: dom, curl, libxml, mbstring, zip
32-
coverage: none
33-
34-
- name: Install dependencies
35-
run: |
36-
composer update --prefer-stable --prefer-dist --no-interaction --no-progress
22+
- name: Fix PHP code style issues
23+
uses: aglipanci/[email protected]
3724

38-
- name: Run CS Fixer
39-
run: ./vendor/bin/php-cs-fixer fix
40-
41-
- name: Commit changes
42-
uses: stefanzweifel/git-auto-commit-action@v4
43-
with:
44-
commit_message: Fix styling
25+
- name: Commit changes
26+
uses: stefanzweifel/git-auto-commit-action@v5
27+
with:
28+
commit_message: Fix styling

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor/
22
coverage/
33
.phpunit.result.cache
4+
.phpunit.cache
45
composer.lock

composer.json

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^7.3|^8.0.2",
21-
"illuminate/auth": "^8.0|^9.0",
22-
"illuminate/console": "^8.0|^9.0",
23-
"illuminate/encryption": "^8.0|^9.0",
24-
"illuminate/support": "^8.0|^9.0",
25-
"illuminate/view": "^8.0|^9.0",
20+
"php": "^8.2",
21+
"illuminate/auth": "^10.0",
22+
"illuminate/console": "^10.0",
23+
"illuminate/encryption": "^10.0",
24+
"illuminate/support": "^10.0",
25+
"illuminate/view": "^10.0",
2626
"laravel/socialite": "^5.0",
27-
"socialiteproviders/gitlab": "^3.1|^4.0",
27+
"socialiteproviders/gitlab": "^4.0",
2828
"socialiteproviders/dropbox": "^4.1"
2929
},
3030
"require-dev": {
31+
"laravel/pint": "^1.14",
3132
"fakerphp/faker": "^1.9.1",
33+
"larastan/larastan": "^2.9",
3234
"mockery/mockery": "^1.4.4",
33-
"phpunit/phpunit": "^9.5.10",
34-
"orchestra/testbench": "^6.15|^7.4",
35-
"friendsofphp/php-cs-fixer": "^2.16|^3.8"
35+
"phpunit/phpunit": "^10.5",
36+
"orchestra/testbench": "^8.22"
3637
},
3738
"autoload": {
3839
"psr-4": {
@@ -44,6 +45,20 @@
4445
"Tests\\": "tests/"
4546
}
4647
},
48+
"scripts": {
49+
"post-autoload-dump": "@composer run prepare",
50+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
51+
"analyse": "vendor/bin/phpstan analyse",
52+
"test": "vendor/bin/phpunit",
53+
"format": "vendor/bin/pint"
54+
},
55+
"config": {
56+
"sort-packages": true,
57+
"allow-plugins": {
58+
"pestphp/pest-plugin": true,
59+
"phpstan/extension-installer": true
60+
}
61+
},
4762
"extra": {
4863
"laravel": {
4964
"providers": [

config/identities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| Encryption Key
88
|--------------------------------------------------------------------------
99
|
10-
| The key is used by the encrypter service and should be set to a
10+
| The key is used by the encrypter service and should be set to a
1111
| random, 32 character string, otherwise encrypted strings will
1212
| not be safe. By default the current APP_KEY is used.
1313
|

phpunit.xml.dist

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
>
12-
<testsuites>
13-
<testsuite name="Package Test Suite">
14-
<directory suffix=".php">./tests/</directory>
15-
</testsuite>
16-
</testsuites>
17-
<php>
18-
<ini name="error_reporting" value="E_ALL"/>
19-
<ini name="display_errors" value="1"/>
20-
<ini name="display_startup_errors" value="1"/>
21-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Package Test Suite">
5+
<directory suffix=".php">./tests/Unit</directory>
6+
</testsuite>
7+
</testsuites>
8+
<php>
9+
<ini name="error_reporting" value="E_ALL"/>
10+
<ini name="display_errors" value="1"/>
11+
<ini name="display_startup_errors" value="1"/>
12+
<env name="DB_CONNECTION" value="testing"/>
13+
</php>
2214
</phpunit>

src/Auth/AuthenticatesUsersWithIdentity.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
trait AuthenticatesUsersWithIdentity
1414
{
15-
use RedirectsUsers, InteractsWithPreviousUrl, FindIdentity;
15+
use FindIdentity, InteractsWithPreviousUrl, RedirectsUsers;
1616

1717
/**
1818
* Redirect the user to the provider authentication page.
@@ -54,7 +54,7 @@ public function login(Request $request, $provider)
5454
// GuzzleHttp\Exception\ClientException
5555
// Client error: `POST https://gitlab.com/oauth/token` resulted in a `401 Unauthorized` response: {"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not ma (truncated...)
5656
// $this->sendFailedLoginResponse
57-
57+
5858
// If we find a registered user with the
5959
// same identity we attempt to login
6060

@@ -63,16 +63,15 @@ public function login(Request $request, $provider)
6363
if (! $user) {
6464
$this->sendFailedLoginResponse($request, $provider);
6565
}
66-
67-
$this->guard()->login($user /*, $remember = false*/);
68-
66+
67+
$this->guard()->login($user /* , $remember = false */);
68+
6969
return $this->sendLoginResponse($request);
7070
}
7171

7272
/**
7373
* Get the failed login response instance.
7474
*
75-
* @param \Illuminate\Http\Request $request
7675
* @return \Symfony\Component\HttpFoundation\Response
7776
*
7877
* @throws \Illuminate\Validation\ValidationException
@@ -87,7 +86,6 @@ protected function sendFailedLoginResponse(Request $request, $provider)
8786
/**
8887
* Send the response after the user was authenticated.
8988
*
90-
* @param \Illuminate\Http\Request $request
9189
* @return \Illuminate\Http\Response
9290
*/
9391
protected function sendLoginResponse(Request $request)
@@ -111,7 +109,7 @@ protected function authenticated(Request $request, $user)
111109
{
112110
//
113111
}
114-
112+
115113
/**
116114
* Get the guard to be used during authentication.
117115
*

src/Auth/ConnectUserIdentity.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
use Illuminate\Http\Response;
77
use Illuminate\Support\Facades\Auth;
88
use Illuminate\Support\Facades\DB;
9-
use Oneofftech\Identities\Facades\IdentityCrypt;
109
use Oneofftech\Identities\Facades\Identity;
10+
use Oneofftech\Identities\Facades\IdentityCrypt;
1111
use Oneofftech\Identities\Support\FindIdentity;
12-
use Oneofftech\Identities\Support\InteractsWithPreviousUrl;
1312
use Oneofftech\Identities\Support\InteractsWithAdditionalAttributes;
13+
use Oneofftech\Identities\Support\InteractsWithPreviousUrl;
1414

1515
trait ConnectUserIdentity
1616
{
17-
use RedirectsUsers, InteractsWithPreviousUrl, InteractsWithAdditionalAttributes, FindIdentity;
17+
use FindIdentity, InteractsWithAdditionalAttributes, InteractsWithPreviousUrl, RedirectsUsers;
1818

1919
/**
2020
* Redirect the user to the Authentication provider authentication page.
@@ -68,29 +68,29 @@ public function connect(Request $request, $provider)
6868

6969
// create or update the user's identity
7070

71-
list($user, $identity) = DB::transaction(function () use ($user, $provider, $oauthUser) {
71+
[$user, $identity] = DB::transaction(function () use ($user, $provider, $oauthUser) {
7272
$identity = $this->createIdentity($user, $provider, $oauthUser);
7373

7474
return [$user, $identity];
7575
});
7676

7777
// todo: event(new Connected($user, $identity));
78-
78+
7979
return $this->sendConnectionResponse($request, $identity);
8080
}
8181

8282
protected function createIdentity($user, $provider, $oauthUser)
8383
{
8484
return $user->identities()->updateOrCreate(
8585
[
86-
'provider'=> $provider,
87-
'provider_id'=> IdentityCrypt::hash($oauthUser->getId())
86+
'provider' => $provider,
87+
'provider_id' => IdentityCrypt::hash($oauthUser->getId()),
8888
],
8989
[
90-
'token'=> IdentityCrypt::encryptString($oauthUser->token),
91-
'refresh_token'=> IdentityCrypt::encryptString($oauthUser->refreshToken),
92-
'expires_at'=> $oauthUser->expiresIn ? now()->addSeconds($oauthUser->expiresIn) : null,
93-
'registration' => false,
90+
'token' => IdentityCrypt::encryptString($oauthUser->token),
91+
'refresh_token' => IdentityCrypt::encryptString($oauthUser->refreshToken),
92+
'expires_at' => $oauthUser->expiresIn ? now()->addSeconds($oauthUser->expiresIn) : null,
93+
'registration' => false,
9494
]
9595
);
9696
}
@@ -111,8 +111,6 @@ protected function sendConnectionResponse(Request $request, $identity)
111111
*
112112
* @param mixed $user
113113
* @param mixed $identity
114-
* @param array $attributes
115-
* @param \Illuminate\Http\Request $request
116114
* @return mixed
117115
*/
118116
protected function connected($user, $identity, array $attributes, Request $request)

0 commit comments

Comments
 (0)