-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from roquie/fixed_middleware_error_exception
Fixed middleware error exception if it uses in the negative case.
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 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
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
53 changes: 53 additions & 0 deletions
53
tests/Functional/Network/Http/Middleware/CallableMiddlewareTest.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,53 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Igni\Tests\Functional\Network\Http\Middleware; | ||
|
||
use Igni\Exception\RuntimeException; | ||
use Igni\Network\Http\Middleware\CallableMiddleware; | ||
use Igni\Network\Http\ServerRequest; | ||
use Igni\Tests\Fixtures\CustomHttpException; | ||
use Igni\Network\Http\Middleware\ErrorMiddleware; | ||
use Mockery; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
final class CallableMiddlewareTest extends TestCase | ||
{ | ||
public function testCanInstantiate(): void | ||
{ | ||
$middleware = new CallableMiddleware(function() {}); | ||
self::assertInstanceOf(CallableMiddleware::class, $middleware); | ||
} | ||
|
||
/** | ||
* @expectedException \Igni\Network\Exception\MiddlewareException | ||
*/ | ||
public function testNegativeUsageCase(): void | ||
{ | ||
$middleware = new CallableMiddleware(function() {}); | ||
$middleware->process( | ||
Mockery::mock(ServerRequestInterface::class), | ||
Mockery::mock(RequestHandlerInterface::class) | ||
); | ||
} | ||
|
||
public function testPositiveUsageCase(): void | ||
{ | ||
$middleware = new CallableMiddleware(function(ServerRequestInterface $request, RequestHandlerInterface $next) { | ||
return $next->handle($request); | ||
}); | ||
|
||
$requestHandler = new class implements RequestHandlerInterface { | ||
public function handle(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
return Mockery::mock(ResponseInterface::class); | ||
} | ||
}; | ||
|
||
$results = $middleware->process(Mockery::mock(ServerRequestInterface::class), $requestHandler); | ||
|
||
$this->assertInstanceOf(ResponseInterface::class, $results); | ||
} | ||
} |