Skip to content

Commit f5551bc

Browse files
committed
Test with data provider
1 parent 9362c02 commit f5551bc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/Routing/RouteRegistrarTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Http\Request;
1010
use Illuminate\Routing\Router;
1111
use Mockery as m;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213
use PHPUnit\Framework\TestCase;
1314
use Stringable;
1415

@@ -127,9 +128,10 @@ public function __toString()
127128
$this->assertSame(['one', 'two'], $this->getRoute()->middleware());
128129
}
129130

130-
public function testMiddlewareAsNull()
131+
#[DataProvider('falsyMiddlewareValues')]
132+
public function testFalsyMiddlewareValuesAreIgnored($middleware)
131133
{
132-
$this->router->middleware(null)->get('users', function () {
134+
$this->router->middleware($middleware)->get('users', function () {
133135
return 'all-users';
134136
});
135137

@@ -138,12 +140,21 @@ public function testMiddlewareAsNull()
138140

139141
$this->router->get('users', function () {
140142
return 'all-users';
141-
})->middleware(null);
143+
})->middleware($middleware);
142144

143145
$this->seeResponse('all-users', Request::create('users', 'GET'));
144146
$this->assertSame([], $this->getRoute()->middleware());
145147
}
146148

149+
public static function falsyMiddlewareValues(): iterable
150+
{
151+
yield [null];
152+
yield [false];
153+
yield [''];
154+
yield [0];
155+
yield [0.0];
156+
}
157+
147158
public function testWithoutMiddlewareRegistration()
148159
{
149160
$this->router->middleware(['one', 'two'])->get('users', function () {

0 commit comments

Comments
 (0)