Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/http/stateless/ApplicationCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ static function () use (&$sequence): void {
$response->getHeaderLine('Content-Type'),
"Expected Content-Type 'application/json; charset=UTF-8' for route 'site/index'.",
);
self::assertJsonStringEqualsJsonString(
<<<JSON
{"hello":"world"}
JSON,
$response->getBody()->getContents(),
"Expected JSON Response body '{\"hello\":\"world\"}'.",
);
self::assertSame(
['before', 'after'],
$sequence,
Expand Down Expand Up @@ -143,6 +150,13 @@ public function testResponseAdapterCachingAndResetBehaviorAcrossMultipleRequests
$response1->getHeaderLine('Content-Type'),
"Expected Content-Type 'application/json; charset=UTF-8' for route 'site/index'.",
);
self::assertJsonStringEqualsJsonString(
<<<JSON
{"hello":"world"}
JSON,
$response1->getBody()->getContents(),
"Expected JSON Response body '{\"hello\":\"world\"}'.",
);

// access the Response component to test adapter behavior
$bridgeResponse1 = $app->response;
Expand Down Expand Up @@ -340,6 +354,13 @@ public function testSetsPsr7RequestWithStatelessAppStartTimeHeader(): void
$response->getHeaderLine('Content-Type'),
"Expected Content-Type 'application/json; charset=UTF-8' for route 'site/index'.",
);
self::assertJsonStringEqualsJsonString(
<<<JSON
{"hello":"world"}
JSON,
$response->getBody()->getContents(),
"Expected JSON Response body '{\"hello\":\"world\"}'.",
);

$psr7Request = $app->request->getPsr7Request();
$statelessAppStartTime = $psr7Request->getHeaderLine('statelessAppStartTime');
Expand Down Expand Up @@ -374,6 +395,13 @@ public function testSetWebAndWebrootAliasesAfterHandleRequest(): void
$response->getHeaderLine('Content-Type'),
"Expected Content-Type 'application/json; charset=UTF-8' for route 'site/index'.",
);
self::assertJsonStringEqualsJsonString(
<<<JSON
{"hello":"world"}
JSON,
$response->getBody()->getContents(),
"Expected JSON Response body '{\"hello\":\"world\"}'.",
);
self::assertSame(
'',
Yii::getAlias('@web'),
Expand Down Expand Up @@ -420,6 +448,13 @@ static function (Event $event) use (&$invocations, &$sequence, &$sender): void {
$response->getHeaderLine('Content-Type'),
"Expected Content-Type 'application/json; charset=UTF-8' for route 'site/index'.",
);
self::assertJsonStringEqualsJsonString(
<<<JSON
{"hello":"world"}
JSON,
$response->getBody()->getContents(),
"Expected JSON Response body '{\"hello\":\"world\"}'.",
);
self::assertSame(
1,
$invocations,
Expand Down
28 changes: 0 additions & 28 deletions tests/http/stateless/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,6 @@ public function testReturnRedirectResponseForSiteRefreshRoute(): void
);
}

/**
* @throws InvalidConfigException if the configuration is invalid or incomplete.
*/
public function testReturnsJsonResponse(): void
{
$app = $this->statelessApplication();

$response = $app->handle(FactoryHelper::createServerRequestCreator()->createFromGlobals());

self::assertSame(
200,
$response->getStatusCode(),
"Response 'status code' should be '200' for successful 'StatelessApplication' handling.",
);
self::assertSame(
'application/json; charset=UTF-8',
$response->getHeaderLine('Content-Type'),
"Response 'Content-Type' should be 'application/json; charset=UTF-8' for JSON output.",
);
self::assertSame(
<<<JSON
{"hello":"world"}
JSON,
$response->getBody()->getContents(),
"Response 'body' should match expected JSON string '{\"hello\":\"world\"}'.",
);
}

/**
* @throws InvalidConfigException if the configuration is invalid or incomplete.
*/
Expand Down
Loading