-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.5] Add withMiddleware function in MakesHttpRequests (#22060)
* Add withMiddleware function inMakesHttpRequests and add tests for with and without methods. * Update MakesHttpRequests.php * Update MakesHttpRequests.php * Fix style.
- Loading branch information
1 parent
7c3443b
commit 47a543f
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Foundation\Http\Middleware; | ||
|
||
use Orchestra\Testbench\TestCase; | ||
|
||
class MakesHttpRequestsTest extends TestCase | ||
{ | ||
public function testWithoutAndWithMiddleware() | ||
{ | ||
$this->assertFalse($this->app->has('middleware.disable')); | ||
|
||
$this->withoutMiddleware(); | ||
$this->assertTrue($this->app->has('middleware.disable')); | ||
$this->assertTrue($this->app->make('middleware.disable')); | ||
|
||
$this->withMiddleware(); | ||
$this->assertFalse($this->app->has('middleware.disable')); | ||
} | ||
|
||
public function testWithoutAndWithMiddlewareWithParameter() | ||
{ | ||
$next = function ($request) { | ||
return $request; | ||
}; | ||
|
||
$this->assertFalse($this->app->has(MyMiddleware::class)); | ||
$this->assertEquals( | ||
'fooWithMiddleware', | ||
$this->app->make(MyMiddleware::class)->handle('foo', $next) | ||
); | ||
|
||
$this->withoutMiddleware(MyMiddleware::class); | ||
$this->assertTrue($this->app->has(MyMiddleware::class)); | ||
$this->assertEquals( | ||
'foo', | ||
$this->app->make(MyMiddleware::class)->handle('foo', $next) | ||
); | ||
|
||
$this->withMiddleware(MyMiddleware::class); | ||
$this->assertFalse($this->app->has(MyMiddleware::class)); | ||
$this->assertEquals( | ||
'fooWithMiddleware', | ||
$this->app->make(MyMiddleware::class)->handle('foo', $next) | ||
); | ||
} | ||
} | ||
|
||
class MyMiddleware | ||
{ | ||
public function handle($request, $next) | ||
{ | ||
return $next($request.'WithMiddleware'); | ||
} | ||
} |