Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Apr 12, 2021
1 parent f156a69 commit 54f1269
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
}
},
"mutators": {
"@default": true
"@default": true,
"InstanceOf_": {
"ignoreSourceCodeByRegex": [
"assert\\(.*\\);"
]
}
}
}
30 changes: 25 additions & 5 deletions tests/HasParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 9 additions & 6 deletions tests/Middleware/OptionalRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
//
}
}
}

0 comments on commit 54f1269

Please sign in to comment.