Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Laravel 10/11 #87

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
47 changes: 39 additions & 8 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,51 @@ concurrency:
cancel-in-progress: true

jobs:
code:
name: "Code check"
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@7562253bdc3769847417e3476b501e7126f5d2c0

code_l10:
name: "Code check - Laravel 10"
strategy:
matrix:
phpVersion: [ "8.1", "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^10"
phpVersion: "${{ matrix.phpVersion }}"
secrets: inherit

code_l11:
name: "Code check - Laravel 11"
strategy:
matrix:
phpVersion: [ "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-check.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^11"
phpVersion: "${{ matrix.phpVersion }}"
secrets: inherit

tests_l10:
name: "Tests - Laravel 10"
strategy:
matrix:
phpVersion: [ "8.1", "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^10"
phpVersion: "${{ matrix.phpVersion }}"
secrets: inherit

tests:
name: "Run tests"
tests_l11:
name: "Tests - Laravel 11"
strategy:
matrix:
phpVersion: [ "8.1", "8.2" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@7562253bdc3769847417e3476b501e7126f5d2c0
phpVersion: [ "8.2", "8.3" ]
uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@c6b6e93c92bb9a2be67e5f6f3c3ca8dcb3bec433
with:
composerRequireDev: "laravel/framework:^11"
phpVersion: "${{ matrix.phpVersion }}"
gistID: ${{ vars.GIST_ID }}
gistOnPhpVersion: "8.2"
phpVersion: "${{ matrix.phpVersion }}"
secrets: inherit


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/composer.lock
/vendor
.phpunit.result.cache
.phpunit.cache
/docs/.nuxt
/docs/dist
/docs/node_modules
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ For MakeExpectationCommand we are using stubs. If you want to generate the stub
## Fixes

- `nikic/php-parser` - on `v4.13.0` enum with value named Array fails to be parsed, `v4.14.0` works

## Maintaining multiple Laravel versions

- When dropping support for Laravel version, find any `Remove when dropping support for Laravel x` notes and remove the code.
- When you want to support lower Laravel version (PHPStan), you can copy the typehints (etc) to our implementation. Add `@todo Remove when dropping support for Laravel` comment, or you can update phpstan `
ignoreErrors:` and add same comment.
- Current local installation always install the highest version of the package. If you want to test lower version run `composer update --prefer-lowest`

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,21 @@ Want more tools or want to help? Check [wrk-flow.com](https://wrk-flow.com) or [
- Make caching more reusable and testable -> `CacheMeService`
- Move business logic to `Actions` or `Services`
- Setup Laravel for great docker experience.

## Acknowledgement

This project owes its existence to the generous support of several other impactful projects:

- **[Canvastera](https://canvastera.com)** - Empowering users to craft multimedia posters and share them worldwide. (EDU/Hobby)
- **[Azzurro Travel Agency](https://azzurro.cz)** - Specializing in holidays in Italy.
- **[Redtag Studio](https://redtag.studio)** - Crafting digital products for your enjoyment.

Explore more of our open-source initiatives:

- **[Larastrict](https://larastrict.com)** - Enhancing the Laravel Framework with a suite of convenient tools and packages.
- **[StrictPHP](https://strictphp.com)** - Enabling strictness in PHP projects through a curated set of packages and conventions, fostering the development of robust production-grade applications.
- **[WrkFlow](https://wrk-flow.com)** - Streamlining development workflows with a comprehensive set of tools designed to boost efficiency.

## License

Open-source software licensed under the [MIT License](LICENSE.md). Feel free to use and modify it according to your needs.
13 changes: 13 additions & 0 deletions UPGRADE_1x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Upgrade to 1.x version

Due to the test bench package we have dropped Laravel 9 and PHPUnit 9.

You need to upgrade your test cases to the new version. Data providers are now static methods.

You can use [rector](https://getrector.com/blog/how-to-upgrade-to-phpunit-10-in-diffs) with additional manual changes
like this:

- replace `protected function generateData(): array` with `protected static function generateData(): arrayt`
- replace `public function data(): array` with `public static function data(): array`

Please check the code changes for detailed information.
50 changes: 30 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"name": "wrkflow/larastrict",
"type": "project",
"description": "Package to improve Laravel framework with features to support more strict typed Laravel.",
"keywords": ["framework", "laravel", "php", "strictphp", "strict"],
"keywords": [
"framework",
"laravel",
"php",
"strictphp",
"strict"
],
"license": "MIT",
"homepage": "https://github.com/wrk-flow/larastrict",
"authors": [
Expand All @@ -14,38 +20,39 @@
"require": {
"php": ">=8.1",
"h4kuna/serialize-polyfill": "^0.2.4",
"laravel/framework": "^9",
"psr/log": "^2 | ^3",
"laravel/framework": "^v10.48.4 | ^v11.2.0",
"psr/log": "^3",
"psr/simple-cache": "^3.0"
},
"require-dev": {
"larastrict/conventions": "v1.0.0",
"ext-pdo": "*",
"ext-sqlite3": "*",
"mockery/mockery": "^1.5.0",
"nette/php-generator": "v4.0.5",
"nikic/php-parser": "v4.15.2",
"nunomaduro/larastan": "2.2.9",
"orchestra/testbench": "^v7.13.0",
"phpstan/phpdoc-parser": "^1.13",
"phpstan/phpstan": "1.9.4",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"mockery/mockery": "^1.6",
"nette/php-generator": "^v4.1.4",
"orchestra/testbench": "^v8.22.2 | ^v9.0.3",
"phpstan/phpstan-mockery": "^1.1.0",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpunit/phpunit": "^9.5.27",
"rector/rector": "0.15.1",
"symplify/easy-coding-standard": "11.1.20"
"phpstan/phpstan-phpunit": "^v1.3.16"
},
"scripts": {
"post-autoload-dump": [
"@php ./vendor/bin/testbench package:discover --ansi"
],
"check": "composer lint && composer test && composer lint:stan",
"analyse": "./vendor/bin/phpstan",
"analyse:b": "./vendor/bin/phpstan -b",
"check": [
"@lint",
"@test",
"@analyse"
],
"lint": [
"@lint:fix",
"@lint:upgrade"
],
"lint:check": "./vendor/bin/ecs",
"lint:fix": "./vendor/bin/ecs --fix",
"lint:stan": "./vendor/bin/phpstan",
"lint:upgrade:check": "vendor/bin/rector process --dry-run",
"lint:upgrade": "vendor/bin/rector process",
"lint": "composer lint:upgrade && composer lint:fix && composer lint:stan",
"lint:upgrade:check": "vendor/bin/rector process --dry-run",
"test": "./vendor/bin/phpunit",
"test:stubs": "STUBS_GENERATE=true ./vendor/bin/phpunit",
"test:coverage": "./vendor/bin/phpunit --coverage-text"
Expand Down Expand Up @@ -78,7 +85,10 @@
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
29 changes: 8 additions & 21 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,19 @@

declare(strict_types=1);

use LaraStrict\Conventions\ExtensionFiles;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $containerConfigurator): void {
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::SYMPLIFY);
$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::CLEAN_CODE);

$containerConfigurator->ruleWithConfiguration(ClassAttributesSeparationFixer::class, [
'elements' => [
'const' => 'only_if_meta',
'property' => 'one',
'method' => 'one',
],
]);

$containerConfigurator->parallel();
$containerConfigurator->paths(
[__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php']
);
$containerConfigurator->skip([
YodaStyleFixer::class,
return ECSConfig::configure()
->withRootFiles()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
->withSets([
ExtensionFiles::Ecs
])
->withSkip([
// We want to leave the relative constant path usage
__DIR__ . '/tests/Feature/Testing/Commands/MakeExpectationCommand/*.php',
]);
};
57 changes: 50 additions & 7 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\$createState of method LaraStrict\\\\Context\\\\Services\\\\ContextService\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: LaraStrict\\\\Context\\\\Values\\\\BoolContextValue, Closure\\(Illuminate\\\\Contracts\\\\Container\\\\Container\\)\\: LaraStrict\\\\Context\\\\Values\\\\BoolContextValue given\\.$#"
count: 1
path: src/Context/Services/ContextService.php

-
message: "#^Parameter \\#1 of closure expects TModel of Illuminate\\\\Database\\\\Eloquent\\\\Model, mixed given\\.$#"
count: 1
path: src/Database/Queries/ChunkedModelQueryResult.php

-
message: "#^Parameter \\#1 of closure expects array\\<int\\|string\\>, array\\<int\\<0, max\\>, mixed\\> given\\.$#"
count: 1
path: src/Database/Queries/ChunkedModelQueryResult.php

-
message: "#^Parameter \\#2 \\$callback of method Illuminate\\\\Database\\\\Eloquent\\\\Builder\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\:\\:chunk\\(\\) expects callable\\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\<int, Illuminate\\\\Database\\\\Eloquent\\\\Model\\>, int\\)\\: mixed, Closure\\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\<int, TModel\\>\\)\\: void given\\.$#"
count: 1
path: src/Database/Queries/ChunkedModelQueryResult.php

-
message: "#^Parameter \\#2 \\$callback of method Illuminate\\\\Database\\\\Eloquent\\\\Builder\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>\\:\\:chunkById\\(\\) expects callable\\(Illuminate\\\\Support\\\\Collection\\<int, TModel\\>, int\\)\\: mixed, Closure\\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\<int, TModel\\>\\)\\: void given\\.$#"
count: 1
path: src/Database/Queries/ChunkedModelQueryResult.php

-
message: "#^Access to an undefined property LaraStrict\\\\Http\\\\Resources\\\\JsonResource\\:\\:\\$preserveKeys\\.$#"
count: 1
Expand All @@ -15,6 +40,11 @@ parameters:
count: 1
path: src/Http/Resources/JsonResourceCollection.php

-
message: "#^Parameter \\$getValue of method LaraStrict\\\\Cache\\\\Contracts\\\\CacheMeServiceContract\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: LaraStrict\\\\Providers\\\\Entities\\\\AppServiceProviderEntity, Closure\\(Illuminate\\\\Contracts\\\\Foundation\\\\Application\\)\\: LaraStrict\\\\Providers\\\\Entities\\\\AppServiceProviderEntity given\\.$#"
count: 1
path: src/Providers/Actions/GetAppServiceProviderForClassAction.php

-
message: "#^Cannot cast array\\|string to string\\.$#"
count: 1
Expand All @@ -25,29 +55,42 @@ parameters:
count: 1
path: src/Testing/Actions/ParsePhpDocAction.php

# forward compatibility
-
message: "#^Attribute class PHPUnit\\\\Framework\\\\Attributes\\\\Before does not exist\\.$#"
message: "#^Method LaraStrict\\\\Testing\\\\Assert\\\\AssertExpectationTestCase\\:\\:beforeStartAssertExpectationManager\\(\\) has no return type specified\\.$#"
count: 1
path: src/Testing/Assert/AssertExpectationTestCase.php

-
message: "#^Attribute class PHPUnit\\\\Framework\\\\Attributes\\\\PostCondition does not exist\\.$#"
message: "#^Method Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\IsContext\\:\\:is\\(\\) should return Closure\\(mixed, mixed, mixed, mixed, mixed\\)\\: bool but returns Closure\\(bool\\)\\: bool\\.$#"
count: 1
path: src/Testing/Assert/AssertExpectationTestCase.php
path: tests/Feature/Context/Services/IsContext.php

-
message: "#^Method LaraStrict\\\\Testing\\\\Assert\\\\AssertExpectationTestCase\\:\\:beforeStartAssertExpectationManager\\(\\) has no return type specified\\.$#"
message: "#^Parameter \\$createState of method LaraStrict\\\\Context\\\\Contracts\\\\ContextServiceContract\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue, Closure\\(string\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue given\\.$#"
count: 1
path: src/Testing/Assert/AssertExpectationTestCase.php
# forward compatibility
path: tests/Feature/Context/Services/TestDependencyContext.php

-
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with false and 'Hook should be…' will always evaluate to false\\.$#"
count: 1
path: tests/Feature/Testing/Commands/MakeExpectationCommandRealTest.php

-
message: "#^Call to method LaraStrict\\\\Testing\\\\Laravel\\\\Contracts\\\\View\\\\FactoryAssert\\:\\:exists\\(\\) with 'test' will always evaluate to false\\.$#"
count: 2
path: tests/Feature/Testing/Laravel/Contracts/View/FactoryAssertTest.php

-
message: "#^Method Tests\\\\LaraStrict\\\\Feature\\\\Translations\\\\InvalidServiceProviderTranslations\\:\\:getProviderClass\\(\\) should return class\\-string\\<LaraStrict\\\\Providers\\\\AbstractServiceProvider\\> but returns string\\.$#"
count: 1
path: tests/Feature/Translations/InvalidServiceProviderTranslations.php

-
message: "#^Parameter \\$createState of method LaraStrict\\\\Testing\\\\Context\\\\Contracts\\\\ContextServiceContractAssert\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue, Closure\\(string\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue given\\.$#"
count: 2
path: tests/Unit/Testing/Context/Contracts/ContextServiceContractAssertTest.php

-
message: "#^Parameter \\$is of method LaraStrict\\\\Testing\\\\Context\\\\Contracts\\\\ContextServiceContractAssert\\:\\:is\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: bool, Closure\\(string\\)\\: true given\\.$#"
count: 1
path: tests/Unit/Testing/Context/Contracts/ContextServiceContractAssertTest.php
25 changes: 3 additions & 22 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
includes:
- vendor/nunomaduro/larastan/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-mockery/extension.neon
- phpstan-baseline.neon

parameters:
reportUnmatchedIgnoredErrors: true
level: max

parallel:
processTimeout: 600.0
# Due the tests between Laravel versions
reportUnmatchedIgnoredErrors: true

paths:
- src
- tests

# The level 8 is the highest level
level: 8

# it is impossible to map toArray()
checkMissingIterableValueType: false

excludePaths:
- 'tests/Feature/Testing/Commands/MakeExpectationCommand/*.php'

ignoreErrors:
# CastsAttributes template was added in Laravel 9.49 (remove when we drop L9 support)
-
message: "#^PHPDoc tag @implements contains generic type Illuminate\\\\Contracts\\\\Database\\\\Eloquent\\\\CastsAttributes\\<float, float\\|int\\|string\\|null\\> but interface Illuminate\\\\Contracts\\\\Database\\\\Eloquent\\\\CastsAttributes is not generic\\.$#"
count: 1
path: src/Database/Models/Casts/FloatCast.php
reportUnmatched: false

Loading
Loading