-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from Micro-PHP/1.6.1
v1.6.1 up decoration priority to 1001
- Loading branch information
Showing
3 changed files
with
32 additions
and
43 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
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
use Micro\Plugin\Http\Facade\HttpFacadeInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author Stanislau Komar <[email protected]> | ||
|
@@ -72,44 +73,40 @@ public function testDecorated() | |
/** | ||
* @dataProvider dataProviderException | ||
*/ | ||
public function testExceptionResponse(string $env, string $uri, bool $isFlush, mixed $result, string $format) | ||
public function testExceptionResponse(string $env, string $uri, bool $isFlush, mixed $result, string $format): void | ||
{ | ||
$kernel = $this->createKernel($env); | ||
$request = Request::create($uri); | ||
$request->request->set('_format', $format); | ||
|
||
$isDev = str_starts_with($env, 'dev'); | ||
if (!$isDev) { | ||
$this->expectException(HttpException::class); | ||
} | ||
|
||
preg_match('/\d+/', $uri, $match); | ||
$exceptionCode = (int) $match[0]; | ||
|
||
$this->expectException(HttpException::class); | ||
$this->expectExceptionCode($exceptionCode); | ||
|
||
ob_start(); | ||
|
||
try { | ||
if (!$isDev) { | ||
$response = $kernel->container()->get(HttpFacadeInterface::class) | ||
->execute($request, $isFlush); | ||
} else { | ||
ob_start(); | ||
/** @var Response $response */ | ||
$response = $kernel->container()->get(HttpFacadeInterface::class) | ||
->execute($request, $isFlush); | ||
$flushedContent = ob_get_contents(); | ||
ob_end_clean(); | ||
} | ||
|
||
$flushedContent = ob_get_clean(); | ||
} catch (HttpException $httpException) { | ||
$flushedContent = ob_get_clean(); | ||
|
||
if ($isFlush) { | ||
if ('json' === $format) { | ||
$this->assertJson($flushedContent); | ||
} | ||
$responseContent = $response->getContent(); | ||
|
||
if ('html' === $format) { | ||
$this->assertStringStartsWith('<!--', $flushedContent); | ||
$this->assertStringEndsWith('-->', $flushedContent); | ||
} | ||
} | ||
$this->assertEquals($exceptionCode, $response->getStatusCode()); | ||
|
||
throw $httpException; | ||
if ($isFlush) { | ||
$this->assertEquals($responseContent, $flushedContent); | ||
} | ||
|
||
$responseContent = $response->getContent(); | ||
if ('html' === $format) { | ||
$this->assertStringStartsWith('<!--', $responseContent); | ||
$this->assertStringEndsWith('-->', $responseContent); | ||
|
@@ -118,15 +115,12 @@ public function testExceptionResponse(string $env, string $uri, bool $isFlush, m | |
if ('json' === $format) { | ||
$this->assertJson($responseContent); | ||
} | ||
|
||
$this->assertStringEndsWith($responseContent, $flushedContent); | ||
$this->assertStringStartsWith($responseContent, $flushedContent); | ||
} | ||
|
||
/** | ||
* @dataProvider dataProviderSuccess | ||
*/ | ||
public function testSuccessResponse(string $env, string $uri, bool $isFlush, mixed $result, string $format) | ||
public function testSuccessResponse(string $env, string $uri, bool $isFlush, mixed $result, string $format): void | ||
{ | ||
$kernel = $this->createKernel($env); | ||
$request = Request::create($uri); | ||
|
@@ -139,11 +133,11 @@ public function testSuccessResponse(string $env, string $uri, bool $isFlush, mix | |
|
||
$responseFlushedContent = ob_get_clean(); | ||
|
||
$this->assertEquals($isFlush ? $result : '', $responseFlushedContent); | ||
$this->assertEquals($isFlush ? $result : false, $responseFlushedContent); | ||
$this->assertEquals($result, $response->getContent()); | ||
} | ||
|
||
public function dataProviderSuccess() | ||
public function dataProviderSuccess(): array | ||
{ | ||
return [ | ||
['dev', '/', true, 'Hello, world', 'html'], | ||
|
@@ -159,7 +153,7 @@ public function dataProviderSuccess() | |
]; | ||
} | ||
|
||
public function dataProviderException() | ||
public function dataProviderException(): array | ||
{ | ||
return [ | ||
['dev', '/404', true, null, 'html'], | ||
|