Skip to content

Commit 013cab8

Browse files
Add support Laravel 11 and PHPUnit 10 (#20)
* Bump PHPUnit dependencies * Ignore PHPUnit cache folder * Adopt PHP attributes in test classes * Add return types to test methods * Define test classes as `final` * Only support Laravel 10 and 11 * Migrate PHPUnit XML * Don't use Kernel to test middleware * Update UPGRADE.md * Add Laravel 11 middleware instructions to README --------- Co-authored-by: Shift <[email protected]>
1 parent 7324f4a commit 013cab8

File tree

10 files changed

+142
-153
lines changed

10 files changed

+142
-153
lines changed

.github/workflows/run-tests.yml

+6-17
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,17 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
php: [ 8.0, 8.1 ]
12-
laravel: [ 8.*, 9.*, 10.* ]
11+
php: [ 8.1, 8.2, 8.3 ]
12+
laravel: [ 10.*, 11.* ]
1313
dependency-version: [ prefer-stable ]
1414
exclude:
15-
- laravel: 10.*
16-
php: 8.0
15+
- laravel: 11.*
16+
php: 8.1
1717
include:
18-
- laravel: 7.*
19-
php: 7.2
20-
testbench: 5.*
21-
- laravel: 7.*
22-
php: 8.0
23-
testbench: 5.*
24-
- laravel: 8.*
25-
php: 7.3
26-
testbench: 6.*
27-
- laravel: 8.*
28-
testbench: 6.*
29-
- laravel: 9.*
30-
testbench: 7.*
3118
- laravel: 10.*
3219
testbench: 8.*
20+
- laravel: 11.*
21+
testbench: 9.*
3322

3423
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
3524

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor
22
/phpunit.xml
33
composer.lock
4+
/.phpunit.cache
45
/.phpunit.result.cache

README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Laravel Localizer
22

33
[![GitHub release](https://img.shields.io/github/release/codezero-be/laravel-localizer.svg?style=flat-square)](https://github.com/codezero-be/laravel-localizer/releases)
4-
[![Laravel](https://img.shields.io/badge/laravel-10-red?style=flat-square&logo=laravel&logoColor=white)](https://laravel.com)
4+
[![Laravel](https://img.shields.io/badge/laravel-11-red?style=flat-square&logo=laravel&logoColor=white)](https://laravel.com)
55
[![License](https://img.shields.io/packagist/l/codezero/laravel-localizer.svg?style=flat-square)](LICENSE.md)
66
[![Build Status](https://img.shields.io/github/actions/workflow/status/codezero-be/laravel-localizer/run-tests.yml?style=flat-square&logo=github&logoColor=white&label=tests)](https://github.com/codezero-be/laravel-localizer/actions)
77
[![Code Coverage](https://img.shields.io/codacy/coverage/ad6fcea152b449d380a187a375d0f7d7/master?style=flat-square)](https://app.codacy.com/gh/codezero-be/laravel-localizer)
@@ -19,8 +19,8 @@ Automatically detect and set an app locale that matches your visitor's preferenc
1919

2020
## ✅ Requirements
2121

22-
- PHP >= 7.2.5
23-
- Laravel >= 7.0
22+
- PHP >= 8.1
23+
- Laravel >= 10.0
2424

2525
## ⬆ Upgrade
2626

@@ -39,13 +39,36 @@ Laravel will automatically register the ServiceProvider.
3939

4040
## 🧩 Add Middleware
4141

42-
Add the middleware to the `web` middleware group in `app/Http/Kernel.php`.
42+
By default, the app locale will always be what you configured in `config/app.php`.
43+
To automatically update the app locale, you need to register the middleware in the `web` middleware group.
4344
Make sure to add it after `StartSession` and before `SubstituteBindings`.
4445

4546
The order of the middleware is important if you are using localized route keys (translated slugs)!
4647
The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.
4748

49+
### Laravel 11 and newer:
50+
51+
Add the middleware to the `web` middleware group in `bootstrap/app.php`.
52+
53+
```php
54+
// bootstrap/app.php
55+
->withMiddleware(function (Middleware $middleware) {
56+
$middleware->web(remove: [
57+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
58+
]);
59+
$middleware->web(append: [
60+
\CodeZero\Localizer\Middleware\SetLocale::class,
61+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
62+
]);
63+
})
64+
```
65+
66+
### Laravel 10:
67+
68+
Add the middleware to the `web` middleware group in `app/Http/Kernel.php`.
69+
4870
```php
71+
// app/Http/Kernel.php
4972
protected $middlewareGroups = [
5073
'web' => [
5174
//...

UPGRADE.md

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Upgrade Guide
22

3+
## Upgrading To 3.0 From 2.x
4+
5+
### ➡ Minimum Requirements Updated
6+
7+
Due to PHP and PHPUnit version constraints with Laravel 11, we dropped support for Laravel 7.x, 8.x and 9.x.
8+
9+
- The minimum PHP version required is now 8.1
10+
- The minimum Laravel version required is now 10.0
11+
12+
---
13+
14+
### ➡ Re-register Middleware
15+
16+
Laravel 11 no longer has a `app/Http/Kernel.php` to register middleware.
17+
This is now handled in `bootstrap/app.php`.
18+
19+
🔸 **Actions Required**
20+
21+
If you use Laravel 11, register the middleware in `bootstrap/app.php` as described in the README.
22+
323
## Upgrading To 2.0 From 1.x
424

525
### ➡ Minimum Requirements Updated

composer.json

+5-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^7.2.5|^8.0",
24+
"php": "^8.1",
2525
"codezero/browser-locale": "^3.0",
26-
"illuminate/support": "^7.0|^8.0|^9.0|^10.0"
26+
"illuminate/support": "^10.0|^11.0"
2727
},
2828
"require-dev": {
2929
"mockery/mockery": "^1.3.3",
30-
"orchestra/testbench": "^5.0|^6.0|^7.0|^8.0",
31-
"phpunit/phpunit": "^8.0|^9.0"
30+
"orchestra/testbench": "^8.0|^9.0",
31+
"phpunit/phpunit": "^10.5"
3232
},
3333
"scripts": {
3434
"test": "phpunit"
@@ -53,10 +53,7 @@
5353
"config": {
5454
"preferred-install": "dist",
5555
"sort-packages": true,
56-
"optimize-autoloader": true,
57-
"allow-plugins": {
58-
"kylekatarnls/update-helper": true
59-
}
56+
"optimize-autoloader": true
6057
},
6158
"minimum-stability": "dev",
6259
"prefer-stable": true

phpunit.xml.dist

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
backupGlobals="false"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
96
processIsolation="false"
10-
stopOnFailure="false">
7+
stopOnFailure="false"
8+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
9+
cacheDirectory=".phpunit.cache"
10+
backupStaticProperties="false">
1111
<testsuites>
1212
<testsuite name="Unit">
1313
<directory suffix="Test.php">./tests/Unit</directory>
@@ -16,15 +16,15 @@
1616
<directory suffix="Test.php">./tests/Feature</directory>
1717
</testsuite>
1818
</testsuites>
19-
<filter>
20-
<whitelist processUncoveredFilesFromWhitelist="true">
21-
<directory suffix=".php">./src</directory>
22-
</whitelist>
23-
</filter>
2419
<php>
2520
<env name="APP_ENV" value="testing"/>
2621
<env name="CACHE_DRIVER" value="array"/>
2722
<env name="SESSION_DRIVER" value="array"/>
2823
<env name="QUEUE_DRIVER" value="sync"/>
2924
</php>
25+
<source>
26+
<include>
27+
<directory suffix=".php">./src</directory>
28+
</include>
29+
</source>
3030
</phpunit>

0 commit comments

Comments
 (0)