response.test.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. class ResponseTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Test the Response::make method.
  5. *
  6. * @group laravel
  7. */
  8. public function testMakeMethodProperlySetsContent()
  9. {
  10. $response = Response::make('foo', 201, array('bar' => 'baz'));
  11. $this->assertEquals('foo', $response->content);
  12. $this->assertEquals(201, $response->status);
  13. $this->assertEquals(array('bar' => 'baz'), $response->headers);
  14. }
  15. /**
  16. * Test the Response::view method.
  17. *
  18. * @group laravel
  19. */
  20. public function testViewMethodSetsContentToView()
  21. {
  22. $response = Response::view('home.index', array('name' => 'Taylor'));
  23. $this->assertEquals('home.index', $response->content->view);
  24. $this->assertEquals('Taylor', $response->content->data['name']);
  25. }
  26. /**
  27. * Test the Response::error method.
  28. *
  29. * @group laravel
  30. */
  31. public function testErrorMethodSetsContentToErrorView()
  32. {
  33. $response = Response::error('404', array('name' => 'Taylor'));
  34. $this->assertEquals(404, $response->status);
  35. $this->assertEquals('error.404', $response->content->view);
  36. $this->assertEquals('Taylor', $response->content->data['name']);
  37. }
  38. /**
  39. * Test the Response::prepare method.
  40. *
  41. * @group laravel
  42. */
  43. public function testPrepareMethodCreatesAResponseInstanceFromGivenValue()
  44. {
  45. $response = Response::prepare('Taylor');
  46. $this->assertInstanceOf('Laravel\\Response', $response);
  47. $this->assertEquals('Taylor', $response->content);
  48. $response = Response::prepare(new Response('Taylor'));
  49. $this->assertInstanceOf('Laravel\\Response', $response);
  50. $this->assertEquals('Taylor', $response->content);
  51. }
  52. /**
  53. * Test the Response::message method.
  54. *
  55. * @group laravel
  56. */
  57. public function testMessageReturnsStatusCodeMessage()
  58. {
  59. $this->assertEquals('OK', Response::make('')->message());
  60. }
  61. /**
  62. * Test the Response::header method.
  63. *
  64. * @group laravel
  65. */
  66. public function testHeaderMethodSetsValueInHeaderArray()
  67. {
  68. $response = Response::make('')->header('foo', 'bar');
  69. $this->assertEquals('bar', $response->headers['foo']);
  70. }
  71. /**
  72. * Test the Response::status method.
  73. *
  74. * @group laravel
  75. */
  76. public function testStatusMethodSetsStatusCode()
  77. {
  78. $response = Response::make('')->status(404);
  79. $this->assertEquals(404, $response->status);
  80. }
  81. }