ResponseTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\HTTP;
  4. class ResponseTest extends \PHPUnit\Framework\TestCase
  5. {
  6. public function testConstruct()
  7. {
  8. $response = new Response(200, ['Content-Type' => 'text/xml']);
  9. $this->assertEquals(200, $response->getStatus());
  10. $this->assertEquals('OK', $response->getStatusText());
  11. }
  12. public function testSetStatus()
  13. {
  14. $response = new Response();
  15. $response->setStatus('402 Where\'s my money?');
  16. $this->assertEquals(402, $response->getStatus());
  17. $this->assertEquals('Where\'s my money?', $response->getStatusText());
  18. }
  19. public function testInvalidStatus()
  20. {
  21. $this->expectException('InvalidArgumentException');
  22. $response = new Response(1000);
  23. }
  24. public function testToString()
  25. {
  26. $response = new Response(200, ['Content-Type' => 'text/xml']);
  27. $response->setBody('foo');
  28. $expected = "HTTP/1.1 200 OK\r\n"
  29. ."Content-Type: text/xml\r\n"
  30. ."\r\n"
  31. .'foo';
  32. $this->assertEquals($expected, (string) $response);
  33. }
  34. }