Skip to content

Commit e6bc42d

Browse files
authored
Laravel 11 (#65)
Co-authored-by: peterfox <[email protected]>
1 parent c4dbf92 commit e6bc42d

15 files changed

+107
-94
lines changed

.github/workflows/run-tests.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
os: [ubuntu-latest, windows-latest]
18-
php: [8.3, 8.2, 8.1]
19-
laravel: [9.*, 10.*]
17+
os: [ubuntu-latest]
18+
php: [8.3, 8.2]
19+
laravel: [11.*, 10.*]
2020
dependencies: [lowest, stable]
2121
include:
22-
- laravel: 9.*
23-
testbench: ^7.0
2422
- laravel: 10.*
2523
testbench: ^8.0
26-
- php: 8.3
27-
dependencies: lowest
28-
carbon: ^2.62.1
29-
- php: 8.2
30-
dependencies: lowest
24+
- laravel: 11.*
25+
testbench: 9.*
26+
- dependencies: lowest
3127
carbon: ^2.62.1
3228

3329
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependencies }} - ${{ matrix.os }}
@@ -55,7 +51,7 @@ jobs:
5551
--no-interaction --no-update
5652
5753
- name: Require Minimum Packages for version
58-
if: ${{ (matrix.php == '8.2' || matrix.php == '8.3') && matrix.dependencies == 'lowest' }}
54+
if: ${{ matrix.dependencies == 'lowest' }}
5955
run: >
6056
composer require
6157
"nesbot/carbon:${{ matrix.carbon }}"

composer.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.1",
20-
"illuminate/contracts": "10.*|^9.6"
19+
"php": "^8.2",
20+
"illuminate/contracts": "11.*|10.*"
2121
},
2222
"require-dev": {
23-
"laravel/pint": "^1.2",
24-
"nunomaduro/collision": "^6.0|^5.0",
25-
"nunomaduro/larastan": "^2.0|^1.0",
26-
"orchestra/testbench": "^8.0|^7.0",
27-
"pestphp/pest": "^1.21",
28-
"pestphp/pest-plugin-laravel": "^1.1",
23+
"composer/semver": "^3.0",
24+
"larastan/larastan": "^2.0|^1.0",
25+
"laravel/pint": "^1.0",
26+
"nunomaduro/collision": "^8.0|^7.8|^6.0",
27+
"orchestra/testbench": "^9.0|^8.0|^7.0",
28+
"pestphp/pest": "^1.21|^2.34",
29+
"pestphp/pest-plugin-arch": "^2.6",
30+
"pestphp/pest-plugin-laravel": "^1.1|^2.3",
2931
"phpstan/extension-installer": "^1.1",
3032
"phpstan/phpdoc-parser": "^1.15",
3133
"phpstan/phpstan-deprecation-rules": "^1.0",
32-
"phpstan/phpstan-phpunit": "^1.0",
33-
"phpunit/phpunit": "^9.5.13",
34-
"rector/rector": "^0.14.2",
35-
"spatie/laravel-ray": "^1.26"
34+
"rector/rector": "^1.0"
3635
},
3736
"autoload": {
3837
"psr-4": {
@@ -49,7 +48,7 @@
4948
"lint": "vendor/bin/pint",
5049
"test": "vendor/bin/pest",
5150
"test-coverage": "vendor/bin/pest coverage",
52-
"mod": "vendor/bin/rector"
51+
"fix": "vendor/bin/rector"
5352
},
5453
"config": {
5554
"sort-packages": true,
@@ -69,5 +68,5 @@
6968
}
7069
},
7170
"minimum-stability": "dev",
72-
"prefer-stable": true
71+
"prefer-stable": false
7372
}

rector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
// register a single rule
1616
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
1717
$rectorConfig->rules([
18-
\Rector\PHPUnit\Rector\Class_\AddSeeTestAnnotationRector::class,
19-
\Rector\PHPUnit\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector::class,
18+
\Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector::class,
19+
\Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector::class,
20+
\Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector::class,
21+
\Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector::class,
2022
]);
2123

2224
// define sets of rules
2325
$rectorConfig->sets([
2426
LevelSetList::UP_TO_PHP_80,
2527
\Rector\Set\ValueObject\SetList::PHP_80,
26-
\Rector\PHPUnit\Set\PHPUnitLevelSetList::UP_TO_PHPUNIT_90,
27-
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_90,
28+
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
2829

2930
]);
3031
};

src/FeatureFlagsServiceProvider.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,29 @@ public function register(): void
9696
$this->app->singleton(FeaturesContract::class, Manager::class);
9797
}
9898

99-
$this->app->scoped(MaintenanceRepository::class, function (Container $app) {
100-
return new MaintenanceRepository($app->make(FeaturesContract::class), $app);
101-
});
102-
103-
$this->app->extend(MaintenanceModeManager::class, function (MaintenanceModeManager $manager) {
104-
return $manager->extend('features', function (): MaintenanceMode {
105-
return new MaintenanceDriver(
106-
$this->app->make(MaintenanceRepository::class)
107-
);
108-
});
109-
});
99+
$this->app->scoped(MaintenanceRepository::class, fn (Container $app) => new MaintenanceRepository($app->make(FeaturesContract::class), $app));
100+
101+
$this->app->extend(MaintenanceModeManager::class, fn (MaintenanceModeManager $manager) => $manager->extend('features', fn (): MaintenanceMode => new MaintenanceDriver(
102+
$this->app->make(MaintenanceRepository::class)
103+
)));
110104
}
111105

112106
protected function schedulingMacros()
113107
{
114108
if (! Event::hasMacro('skipWithoutFeature')) {
115109
/** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
116-
Event::macro('skipWithoutFeature', function (string $feature): Event {
110+
Event::macro('skipWithoutFeature', fn (string $feature): Event =>
117111
/** @var Event $this */
118-
return $this->skip(fn () => ! Features::accessible($feature));
119-
});
112+
/** @phpstan-ignore-next-line annoying issue with macros */
113+
$this->skip(fn () => ! Features::accessible($feature)));
120114
}
121115

122116
if (! Event::hasMacro('skipWithFeature')) {
123117
/** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
124-
Event::macro('skipWithFeature', function ($feature): Event {
118+
Event::macro('skipWithFeature', fn ($feature): Event =>
125119
/** @var Event $this */
126-
return $this->skip(fn () => Features::accessible($feature));
127-
});
120+
/** @phpstan-ignore-next-line annoying issue with macros */
121+
$this->skip(fn () => Features::accessible($feature)));
128122
}
129123
}
130124

src/Gateways/GateGateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function generateKey(string $feature): string
3434
return md5($feature);
3535
}
3636

37-
return implode(':', [md5($feature), get_class($model), $model->getKey()]);
37+
return implode(':', [md5($feature), $model::class, $model->getKey()]);
3838
}
3939
}

src/Support/MaintenanceScenario.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Contracts\Support\Arrayable;
66

7+
/**
8+
* @see \YlsIdeas\FeatureFlags\Tests\Support\MaintenanceScenarioTest
9+
*/
710
class MaintenanceScenario implements Arrayable
811
{
912
public string $feature;

tests/ArchTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
arch('globals')
4+
->expect(['dd', 'dump'])
5+
->not->toBeUsed();

tests/FeatureFlagsServiceProviderTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ protected function getPackageProviders($app): array
1818
];
1919
}
2020

21-
/**
22-
* @before
23-
*/
21+
#[\PHPUnit\Framework\Attributes\Before]
2422
protected function cleanUp(): void
2523
{
2624
$this->afterApplicationCreated(function () {

tests/MaintenanceModeTest.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
namespace YlsIdeas\FeatureFlags\Tests;
44

55
use Illuminate\Contracts\Http\Kernel;
6+
use Illuminate\Foundation\Configuration\Middleware;
67
use Illuminate\Support\Facades\Route;
8+
9+
use function Orchestra\Testbench\after_resolving;
10+
711
use Orchestra\Testbench\TestCase;
812
use YlsIdeas\FeatureFlags\Facades\Features;
913
use YlsIdeas\FeatureFlags\FeatureFlagsServiceProvider;
@@ -19,7 +23,7 @@ public function test_maintenance_mode_enabled()
1923
Route::get('/', fn () => 'Foo Bar');
2024

2125
$this->get('/')
22-
->assertStatus(503);
26+
->assertServiceUnavailable();
2327

2428
Features::assertAccessed('system.down');
2529
}
@@ -70,9 +74,7 @@ public function test_upon_activation()
7074
$this->assertTrue($called);
7175
}
7276

73-
/**
74-
* @dataProvider exceptsValues
75-
*/
77+
#[\PHPUnit\Framework\Attributes\DataProvider('exceptsValues')]
7678
public function test_maintenance_mode_respects_excepts_values(string $path, int $status)
7779
{
7880
Features::fake(['system.down' => true]);
@@ -83,13 +85,15 @@ public function test_maintenance_mode_respects_excepts_values(string $path, int
8385
Route::get('/', fn () => 'Foo Bar');
8486
Route::get('/test', fn () => 'Foo Bar Foo');
8587

86-
$this->get($path)
88+
$this
89+
->withoutExceptionHandling([\Symfony\Component\HttpKernel\Exception\HttpException::class])
90+
->get($path)
8791
->assertStatus($status);
8892

8993
Features::assertAccessed('system.down');
9094
}
9195

92-
public function exceptsValues(): \Generator
96+
public static function exceptsValues(): \Generator
9397
{
9498
yield 'blocked' => [
9599
'/', 503,
@@ -122,7 +126,7 @@ protected function defineEnvironment($app): void
122126
}
123127

124128
/**
125-
* Resolve application HTTP Kernel implementation.
129+
* Required override for Pre Laravel 11
126130
*
127131
* @param \Illuminate\Foundation\Application $app
128132
* @return void
@@ -137,6 +141,26 @@ protected function resolveApplicationHttpKernel($app)
137141
);
138142
}
139143

144+
/**
145+
* Required override for Laravel 11
146+
*
147+
* @param \Illuminate\Foundation\Application $app
148+
* @return void
149+
*/
150+
protected function resolveApplicationHttpMiddlewares($app)
151+
{
152+
after_resolving($app, Kernel::class, function ($kernel, $app) {
153+
/** @var \Illuminate\Foundation\Http\Kernel $kernel */
154+
$middleware = new Middleware();
155+
156+
$kernel->setGlobalMiddleware([
157+
\YlsIdeas\FeatureFlags\Middlewares\PreventRequestsDuringMaintenance::class,
158+
]);
159+
$kernel->setMiddlewareGroups($middleware->getMiddlewareGroups());
160+
$kernel->setMiddlewareAliases($middleware->getMiddlewareAliases());
161+
});
162+
}
163+
140164
protected function getPackageProviders($app): array
141165
{
142166
return [

tests/ManagerTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
use YlsIdeas\FeatureFlags\Events\FeatureSwitchedOn;
1616
use YlsIdeas\FeatureFlags\Manager;
1717

18-
/**
19-
* @covers \YlsIdeas\FeatureFlags\Manager
20-
*/
18+
#[\PHPUnit\Framework\Attributes\CoversClass(\YlsIdeas\FeatureFlags\Manager::class)]
2119
class ManagerTest extends TestCase
2220
{
2321
use MockeryPHPUnitIntegration;
@@ -141,9 +139,7 @@ public function test_it_can_turn_off_features(): void
141139
$manager->turnOff('test', 'my-feature');
142140
}
143141

144-
/**
145-
* @dataProvider services
146-
*/
142+
#[\PHPUnit\Framework\Attributes\DataProvider('services')]
147143
public function test_it_can_flag_parts_of_the_package_to_be_turned_off($item): void
148144
{
149145
$manager = new Manager($this->container, \Mockery::mock(Dispatcher::class));
@@ -155,7 +151,7 @@ public function test_it_can_flag_parts_of_the_package_to_be_turned_off($item): v
155151
$this->assertFalse($manager->{"uses$item"}());
156152
}
157153

158-
public function services(): array
154+
public static function services(): array
159155
{
160156
return [
161157
['Blade'],

0 commit comments

Comments
 (0)