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 + { + // + } } }