ServerRequestTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. use RingCentral\Psr7\ServerRequest;
  3. class ServerRequestTest extends \PHPUnit_Framework_TestCase
  4. {
  5. private $request;
  6. public function setUp()
  7. {
  8. $this->request = new ServerRequest('GET', 'http://localhost');
  9. }
  10. public function testGetNoAttributes()
  11. {
  12. $this->assertEquals(array(), $this->request->getAttributes());
  13. }
  14. public function testWithAttribute()
  15. {
  16. $request = $this->request->withAttribute('hello', 'world');
  17. $this->assertNotSame($request, $this->request);
  18. $this->assertEquals(array('hello' => 'world'), $request->getAttributes());
  19. }
  20. public function testGetAttribute()
  21. {
  22. $request = $this->request->withAttribute('hello', 'world');
  23. $this->assertNotSame($request, $this->request);
  24. $this->assertEquals('world', $request->getAttribute('hello'));
  25. }
  26. public function testGetDefaultAttribute()
  27. {
  28. $request = $this->request->withAttribute('hello', 'world');
  29. $this->assertNotSame($request, $this->request);
  30. $this->assertEquals(null, $request->getAttribute('hi', null));
  31. }
  32. public function testWithoutAttribute()
  33. {
  34. $request = $this->request->withAttribute('hello', 'world');
  35. $request = $request->withAttribute('test', 'nice');
  36. $request = $request->withoutAttribute('hello');
  37. $this->assertNotSame($request, $this->request);
  38. $this->assertEquals(array('test' => 'nice'), $request->getAttributes());
  39. }
  40. public function testWithCookieParams()
  41. {
  42. $request = $this->request->withCookieParams(array('test' => 'world'));
  43. $this->assertNotSame($request, $this->request);
  44. $this->assertEquals(array('test' => 'world'), $request->getCookieParams());
  45. }
  46. public function testWithQueryParams()
  47. {
  48. $request = $this->request->withQueryParams(array('test' => 'world'));
  49. $this->assertNotSame($request, $this->request);
  50. $this->assertEquals(array('test' => 'world'), $request->getQueryParams());
  51. }
  52. public function testWithUploadedFiles()
  53. {
  54. $request = $this->request->withUploadedFiles(array('test' => 'world'));
  55. $this->assertNotSame($request, $this->request);
  56. $this->assertEquals(array('test' => 'world'), $request->getUploadedFiles());
  57. }
  58. public function testWithParsedBody()
  59. {
  60. $request = $this->request->withParsedBody(array('test' => 'world'));
  61. $this->assertNotSame($request, $this->request);
  62. $this->assertEquals(array('test' => 'world'), $request->getParsedBody());
  63. }
  64. }