HeaderLocationTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace GuzzleHttp\Tests\Command\Guzzle\RequestLocation;
  3. use GuzzleHttp\Command\Command;
  4. use GuzzleHttp\Command\Guzzle\Operation;
  5. use GuzzleHttp\Command\Guzzle\Parameter;
  6. use GuzzleHttp\Command\Guzzle\RequestLocation\HeaderLocation;
  7. use GuzzleHttp\Psr7\Request;
  8. /**
  9. * @covers \GuzzleHttp\Command\Guzzle\RequestLocation\HeaderLocation
  10. * @covers \GuzzleHttp\Command\Guzzle\RequestLocation\AbstractLocation
  11. */
  12. class HeaderLocationTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @group RequestLocation
  16. */
  17. public function testVisitsLocation()
  18. {
  19. $location = new HeaderLocation('header');
  20. $command = new Command('foo', ['foo' => 'bar']);
  21. $request = new Request('POST', 'http://httbin.org');
  22. $param = new Parameter(['name' => 'foo']);
  23. $request = $location->visit($command, $request, $param);
  24. $header = $request->getHeader('foo');
  25. $this->assertTrue(is_array($header));
  26. $this->assertArraySubset([0 => 'bar'], $request->getHeader('foo'));
  27. }
  28. /**
  29. * @group RequestLocation
  30. */
  31. public function testAddsAdditionalProperties()
  32. {
  33. $location = new HeaderLocation('header');
  34. $command = new Command('foo', ['foo' => 'bar']);
  35. $command['add'] = 'props';
  36. $operation = new Operation([
  37. 'additionalParameters' => [
  38. 'location' => 'header'
  39. ]
  40. ]);
  41. $request = new Request('POST', 'http://httbin.org');
  42. $request = $location->after($command, $request, $operation);
  43. $header = $request->getHeader('add');
  44. $this->assertTrue(is_array($header));
  45. $this->assertArraySubset([0 => 'props'], $header);
  46. }
  47. }