forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponseTest.php
More file actions
executable file
·84 lines (65 loc) · 2.48 KB
/
HttpResponseTest.php
File metadata and controls
executable file
·84 lines (65 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
use Mockery as m;
use Illuminate\Support\Contracts\JsonableInterface;
class HttpResponseTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testJsonResponsesAreConvertedAndHeadersAreSet()
{
$response = new Illuminate\Http\Response(new JsonableStub);
$this->assertEquals('foo', $response->getContent());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
$response = new Illuminate\Http\Response();
$response->setContent(array('foo' => 'bar'));
$this->assertEquals('{"foo":"bar"}', $response->getContent());
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
}
public function testRenderablesAreRendered()
{
$mock = m::mock('Illuminate\Support\Contracts\RenderableInterface');
$mock->shouldReceive('render')->once()->andReturn('foo');
$response = new Illuminate\Http\Response($mock);
$this->assertEquals('foo', $response->getContent());
}
public function testHeader()
{
$response = new Illuminate\Http\Response();
$this->assertNull($response->headers->get('foo'));
$response->header('foo', 'bar');
$this->assertEquals('bar', $response->headers->get('foo'));
$response->header('foo', 'baz', false);
$this->assertEquals('bar', $response->headers->get('foo'));
$response->header('foo', 'baz');
$this->assertEquals('baz', $response->headers->get('foo'));
}
public function testWithCookie()
{
$response = new Illuminate\Http\Response();
$this->assertEquals(0, count($response->headers->getCookies()));
$this->assertEquals($response, $response->withCookie(new \Symfony\Component\HttpFoundation\Cookie('foo', 'bar')));
$cookies = $response->headers->getCookies();
$this->assertEquals(1, count($cookies));
$this->assertEquals('foo', $cookies[0]->getName());
$this->assertEquals('bar', $cookies[0]->getValue());
}
public function testGetOriginalContent()
{
$arr = array('foo' => 'bar');
$response = new Illuminate\Http\Response();
$response->setContent($arr);
$this->assertSame($arr, $response->getOriginalContent());
}
public function testSetAndRetrieveStatusCode()
{
$response = new Illuminate\Http\Response('foo', 404);
$this->assertSame(404, $response->getStatusCode());
$response = new Illuminate\Http\Response('foo');
$response->setStatusCode(404);
$this->assertSame(404, $response->getStatusCode());
}
}
class JsonableStub implements JsonableInterface {
public function toJson($options = 0) { return 'foo'; }
}