Rfc3986SerializerTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace GuzzleHttp\Tests\Command\Guzzle\QuerySerializer;
  3. use GuzzleHttp\Command\Guzzle\QuerySerializer\Rfc3986Serializer;
  4. class Rfc3986SerializerTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function queryProvider()
  7. {
  8. return [
  9. [['foo' => 'bar'], 'foo=bar'],
  10. [['foo' => [1, 2]], 'foo[0]=1&foo[1]=2'],
  11. [['foo' => ['bar' => 'baz', 'bim' => [4, 5]]], 'foo[bar]=baz&foo[bim][0]=4&foo[bim][1]=5']
  12. ];
  13. }
  14. /**
  15. * @dataProvider queryProvider
  16. */
  17. public function testSerializeQueryParams(array $params, $expectedResult)
  18. {
  19. $serializer = new Rfc3986Serializer();
  20. $result = $serializer->aggregate($params);
  21. $this->assertEquals($expectedResult, urldecode($result));
  22. }
  23. public function testCanRemoveNumericIndices()
  24. {
  25. $serializer = new Rfc3986Serializer(true);
  26. $result = $serializer->aggregate(['foo' => ['bar', 'baz'], 'bar' => ['bim' => [4, 5]]]);
  27. $this->assertEquals('foo[]=bar&foo[]=baz&bar[bim][]=4&bar[bim][]=5', urldecode($result));
  28. }
  29. }