|
13 | 13 |
|
14 | 14 | use Symfony\Component\HttpFoundation\JsonResponse; |
15 | 15 |
|
16 | | -/** |
17 | | - * @covers Symfony\Component\HttpFoundation\JsonResponse::__construct |
18 | | - * @covers Symfony\Component\HttpFoundation\JsonResponse::setData |
19 | | - * @covers Symfony\Component\HttpFoundation\JsonResponse::setCallback |
20 | | - */ |
21 | 16 | class JsonResponseTest extends \PHPUnit_Framework_TestCase |
22 | 17 | { |
23 | 18 | public function testConstructorEmptyCreatesJsonObject() |
@@ -89,6 +84,73 @@ public function testCreate() |
89 | 84 | $this->assertEquals(204, $response->getStatusCode()); |
90 | 85 | } |
91 | 86 |
|
| 87 | + public function testStaticCreateEmptyJsonObject() |
| 88 | + { |
| 89 | + $response = JsonResponse::create(); |
| 90 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 91 | + $this->assertSame('{}', $response->getContent()); |
| 92 | + } |
| 93 | + |
| 94 | + public function testStaticCreateJsonArray() |
| 95 | + { |
| 96 | + $response = JsonResponse::create(array(0, 1, 2, 3)); |
| 97 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 98 | + $this->assertSame('[0,1,2,3]', $response->getContent()); |
| 99 | + } |
| 100 | + |
| 101 | + public function testStaticCreateJsonObject() |
| 102 | + { |
| 103 | + $response = JsonResponse::create(array('foo' => 'bar')); |
| 104 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 105 | + $this->assertSame('{"foo":"bar"}', $response->getContent()); |
| 106 | + } |
| 107 | + |
| 108 | + public function testStaticCreateWithSimpleTypes() |
| 109 | + { |
| 110 | + $response = JsonResponse::create('foo'); |
| 111 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 112 | + $this->assertSame('"foo"', $response->getContent()); |
| 113 | + |
| 114 | + $response = JsonResponse::create(0); |
| 115 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 116 | + $this->assertSame('0', $response->getContent()); |
| 117 | + |
| 118 | + $response = JsonResponse::create(0.1); |
| 119 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 120 | + $this->assertSame('0.1', $response->getContent()); |
| 121 | + |
| 122 | + $response = JsonResponse::create(true); |
| 123 | + $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response); |
| 124 | + $this->assertSame('true', $response->getContent()); |
| 125 | + } |
| 126 | + |
| 127 | + public function testStaticCreateWithCustomStatus() |
| 128 | + { |
| 129 | + $response = JsonResponse::create(array(), 202); |
| 130 | + $this->assertSame(202, $response->getStatusCode()); |
| 131 | + } |
| 132 | + |
| 133 | + public function testStaticCreateAddsContentTypeHeader() |
| 134 | + { |
| 135 | + $response = JsonResponse::create(); |
| 136 | + $this->assertSame('application/json', $response->headers->get('Content-Type')); |
| 137 | + } |
| 138 | + |
| 139 | + public function testStaticCreateWithCustomHeaders() |
| 140 | + { |
| 141 | + $response = JsonResponse::create(array(), 200, array('ETag' => 'foo')); |
| 142 | + $this->assertSame('application/json', $response->headers->get('Content-Type')); |
| 143 | + $this->assertSame('foo', $response->headers->get('ETag')); |
| 144 | + } |
| 145 | + |
| 146 | + public function testStaticCreateWithCustomContentType() |
| 147 | + { |
| 148 | + $headers = array('Content-Type' => 'application/vnd.acme.blog-v1+json'); |
| 149 | + |
| 150 | + $response = JsonResponse::create(array(), 200, $headers); |
| 151 | + $this->assertSame('application/vnd.acme.blog-v1+json', $response->headers->get('Content-Type')); |
| 152 | + } |
| 153 | + |
92 | 154 | public function testSetCallback() |
93 | 155 | { |
94 | 156 | $response = JsonResponse::create(array('foo' => 'bar'))->setCallback('callback'); |
|
0 commit comments