8000 Jsonresponse fix by kanariezwart · Pull Request #16551 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Jsonresponse fix #16551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[HttpFoundation] JsonResponse.php. Updated JsonResponseTest
Added new tests for testing setting content and setting data after setting EncodingOptions
  • Loading branch information
kanariezwart committed Nov 16, 2015
commit 7ea082365b495265ea1b5fcfad63e037bbc71c4f
24 changes: 24 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,30 @@ public function testSetContentJsonSerializeError()

JsonResponse::create($serializable);
}

public function testSetDataAfterSettingEncodingOptions()
{
$response = new JsonResponse();
$response->setData(array(array(1, 2, 3)));

$this->assertEquals('[[1,2,3]]', $response->getContent());

$response->setEncodingOptions(JSON_FORCE_OBJECT);
$response->setData(array(array(4, 5, 6)));
$this->assertEquals('{"0":{"0":4,"1":5,"2":6}}', $response->getContent());
}

public function testSetContentAfterSettingEncodingOptions()
{
$response = new JsonResponse();
$response->setData(array(array(1, 2, 3)));

$this->assertEquals('[[1,2,3]]', $response->getContent());

$response->setEncodingOptions(JSON_PRETTY_PRINT);
$response->setContent("['baz' => ['foo' => 'bar']]");
$this->assertEquals("['baz' => ['foo' => 'bar']]", $response->getContent());
}
}

if (interface_exists('JsonSerializable')) {
Expand Down
0