From fc603799c6487d3a55672c610239c79d909b3007 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Mon, 14 Dec 2020 20:51:22 +1100 Subject: [PATCH 1/5] wip --- .github/workflows/main.yml | 24 +++++++++++++++--------- composer.json | 2 +- readme.md | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4c07400..6b8a983 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,14 +20,14 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '^8.0' coverage: pcov - name: Cache dependencies uses: actions/cache@v1 with: path: ~/.composer/cache/files - key: dependencies-composer-${{ hashFiles('composer.json') }}-v1 + key: dependencies-composer-${{ hashFiles('composer.json') }}-v2 - name: Install dependencies run: composer install --no-suggest --no-interaction --verbose @@ -64,7 +64,7 @@ jobs: name: 'Test suite on PHP: ${{ matrix.php }}; Laravel: ${{ matrix.laravel }}; Dependecies: ${{ matrix.dependency-version }}' strategy: matrix: - php: ['7.1', '7.2', '7.3', '7.4'] + php: ['^7.1', '^7.2', '^7.3', '^7.4', '^8.0'] laravel: ['~5.5.0', '~5.6.0', '~5.7.0', '~5.8.0', '^6.0', '^7.0', '^8.0'] dependency-version: ['prefer-lowest', 'prefer-stable'] include: @@ -84,15 +84,21 @@ jobs: testbench: '^6.0' exclude: - laravel: '~5.3.0' - php: '7.2' + php: '^7.2' - laravel: '^6.0' - php: '7.1' + php: '^7.1' - laravel: '^7.0' - php: '7.1' + php: '^7.1' - laravel: '^8.0' - php: '7.1' + php: '^7.1' - laravel: '^8.0' - php: '7.2' + php: '^7.2' + - laravel: '~5.6.0' + php: '^8.0' + - laravel: '~5.7.0' + php: '^8.0' + - laravel: '~5.8.0' + php: '^8.0' steps: - name: checkout code @@ -108,7 +114,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.composer/cache/files - key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-v1 + key: dependencies-${{ matrix.dependency-version }}-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-v2 - name: Install dependencies run: | diff --git a/composer.json b/composer.json index 131d3e8..dd9730d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^7.1", + "php": "^7.1 || ^8.0", "illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0 || ^7.0 || ^8.0" }, "require-dev": { diff --git a/readme.md b/readme.md index c0a54d1..350e5f2 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Read more about the why in my blog post [Rethinking Laravel's middleware argumen ## Version support -- **PHP**: 7.1, 7.2, 7.3, 7.4 +- **PHP**: 7.1, 7.2, 7.3, 7.4, 8.0 - **Laravel**: 5.5, 5.6, 5.7, 5.8, 6.0, 7.0, 8.0 ## Installation From fee8a69922cbbd7e1b3751892fcab1414d93adda Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Mon, 14 Dec 2020 21:00:40 +1100 Subject: [PATCH 2/5] standardise php version constraint --- .github/workflows/main.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6b8a983..5272c28 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '^8.0' + php-version: '8.0' coverage: pcov - name: Cache dependencies @@ -64,7 +64,7 @@ jobs: name: 'Test suite on PHP: ${{ matrix.php }}; Laravel: ${{ matrix.laravel }}; Dependecies: ${{ matrix.dependency-version }}' strategy: matrix: - php: ['^7.1', '^7.2', '^7.3', '^7.4', '^8.0'] + php: ['7.1', '7.2', '7.3', '7.4', '8.0'] laravel: ['~5.5.0', '~5.6.0', '~5.7.0', '~5.8.0', '^6.0', '^7.0', '^8.0'] dependency-version: ['prefer-lowest', 'prefer-stable'] include: @@ -84,21 +84,21 @@ jobs: testbench: '^6.0' exclude: - laravel: '~5.3.0' - php: '^7.2' + php: '7.2' - laravel: '^6.0' - php: '^7.1' + php: '7.1' - laravel: '^7.0' - php: '^7.1' + php: '7.1' - laravel: '^8.0' - php: '^7.1' + php: '7.1' - laravel: '^8.0' - php: '^7.2' + php: '7.2' - laravel: '~5.6.0' - php: '^8.0' + php: '8.0' - laravel: '~5.7.0' - php: '^8.0' + php: '8.0' - laravel: '~5.8.0' - php: '^8.0' + php: '8.0' steps: - name: checkout code From 42a06a1b4ec05f313d007461a4836742ac7d9209 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Mon, 14 Dec 2020 21:39:09 +1100 Subject: [PATCH 3/5] wip --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5272c28..c86f4c2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '7.4' coverage: pcov - name: Cache dependencies From f156a69d353b9643751b1d5e836c1d14018ab97c Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 4 Feb 2021 14:19:57 +1100 Subject: [PATCH 4/5] wip --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c86f4c2..aad0ec5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.0' coverage: pcov - name: Cache dependencies @@ -93,6 +93,8 @@ jobs: php: '7.1' - laravel: '^8.0' php: '7.2' + - laravel: '~5.5.0' + php: '8.0' - laravel: '~5.6.0' php: '8.0' - laravel: '~5.7.0' From 54f12691a9fe4e278c6f9c84dd4ef97308fb45a1 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 13 Apr 2021 09:06:36 +1000 Subject: [PATCH 5/5] wip --- composer.json | 2 +- infection.json.dist | 7 ++++++- tests/HasParametersTest.php | 30 ++++++++++++++++++++++----- tests/Middleware/OptionalRequired.php | 15 ++++++++------ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index dd9730d..0009490 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "ergebnis/composer-normalize": "^2.0", - "infection/infection": "^0.16", + "infection/infection": "^0.21", "orchestra/testbench": "^6.0", "phpstan/phpstan": "^0.12", "phpunit/phpunit": "^9.0", diff --git a/infection.json.dist b/infection.json.dist index 7b603a5..0387cbc 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -11,6 +11,11 @@ } }, "mutators": { - "@default": true + "@default": true, + "InstanceOf_": { + "ignoreSourceCodeByRegex": [ + "assert\\(.*\\);" + ] + } } } diff --git a/tests/HasParametersTest.php b/tests/HasParametersTest.php index a11425a..0eb5d51 100644 --- a/tests/HasParametersTest.php +++ b/tests/HasParametersTest.php @@ -7,6 +7,7 @@ use ErrorException; use Illuminate\Support\Collection; use Orchestra\Testbench\TestCase; +use const PHP_MAJOR_VERSION; use Tests\Middleware\Basic; use Tests\Middleware\Optional; use Tests\Middleware\OptionalRequired; @@ -76,14 +77,26 @@ public function testListDoesNotAcceptSubArray(): void Basic::in(['laravel', ['vue', 'react']]); } - public function testListDetectsRequiredParametersThatHaveNotBeenProvided(): void + public function testListDetectsRequiredParametersThatHaveNotBeenProvidedAfterAnOptional(): void { + if (PHP_MAJOR_VERSION >= 8) { + $this->markTestSkipped('Tests functionality deprecated in PHP 8.0'); + } + $this->expectException(TypeError::class); $this->expectExceptionMessage('Missing required argument $required for middleware Tests\\Middleware\\OptionalRequired::handle()'); OptionalRequired::in(['laravel']); } + public function testListDetectsRequiredParametersThatHaveNotBeenProvided(): void + { + $this->expectException(TypeError::class); + $this->expectExceptionMessage('Missing required argument $required for middleware Tests\\Middleware\\Required::handle()'); + + Required::in([]); + } + public function testListDoesNotAcceptAssociativeArray(): void { $this->expectException(TypeError::class); @@ -181,11 +194,14 @@ public function testMap(): void $result = Variadic::with(['variadic' => false]); $this->assertSame('Tests\\Middleware\\Variadic:0', $result); - $result = OptionalRequired::with(['required' => 'laravel']); - $this->assertSame('Tests\\Middleware\\OptionalRequired:default,laravel', $result); + if (PHP_MAJOR_VERSION < 8) { + // Tests functionality deprecated in PHP 8.0 + $result = OptionalRequired::with(['required' => 'laravel']); + $this->assertSame('Tests\\Middleware\\OptionalRequired:default,laravel', $result); - $result = OptionalRequired::with(['required' => 'laravel', 'optional' => 'vue']); - $this->assertSame('Tests\\Middleware\\OptionalRequired:vue,laravel', $result); + $result = OptionalRequired::with(['required' => 'laravel', 'optional' => 'vue']); + $this->assertSame('Tests\\Middleware\\OptionalRequired:vue,laravel', $result); + } $result = RequiredOptionalVariadic::with(['required' => 'laravel']); $this->assertSame('Tests\\Middleware\\RequiredOptionalVariadic:laravel,default', $result); @@ -261,6 +277,10 @@ public function testVariadicDoesNotAcceptSubArray(): void public function testMiddlewareThatUsesFuncGetArgsCanAccessArgumentsThatAreNotPassedAsParameters(): void { + if (PHP_MAJOR_VERSION >= 8) { + $this->markTestSkipped('Tests functionality deprecated in PHP 8.0'); + } + $result = OptionalRequired::in(['laravel', 'vue', 'tailwind']); $this->assertSame('Tests\\Middleware\\OptionalRequired:laravel,vue,tailwind', $result); } diff --git a/tests/Middleware/OptionalRequired.php b/tests/Middleware/OptionalRequired.php index 21be7ac..9ab14af 100644 --- a/tests/Middleware/OptionalRequired.php +++ b/tests/Middleware/OptionalRequired.php @@ -6,14 +6,17 @@ use Closure; use Illuminate\Http\Request; +use const PHP_MAJOR_VERSION; use TiMacDonald\Middleware\HasParameters; -class OptionalRequired -{ - use HasParameters; - - public function handle(Request $request, Closure $next, string $optional = 'default', string $required): void +if (PHP_MAJOR_VERSION < 8) { + class OptionalRequired { - // + use HasParameters; + + public function handle(Request $request, Closure $next, string $optional, string $required): void + { + // + } } }