JSONPathDashedIndexTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Flow\JSONPath\Test;
  3. use Flow\JSONPath\JSONPath;
  4. class JSONPathDashedIndexTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function indexDataProvider()
  7. {
  8. return [
  9. // path, data, expected
  10. [
  11. '$.data[test-test-test]',
  12. [
  13. 'data' => [
  14. 'test-test-test' => 'foo'
  15. ]
  16. ],
  17. [
  18. 'foo'
  19. ]
  20. ],
  21. [
  22. '$.data[40f35757-2563-4790-b0b1-caa904be455f]',
  23. [
  24. 'data' => [
  25. '40f35757-2563-4790-b0b1-caa904be455f' => 'bar'
  26. ]
  27. ],
  28. [
  29. 'bar'
  30. ]
  31. ]
  32. ];
  33. }
  34. /** @dataProvider indexDataProvider */
  35. public function testSlice($path, $data, $expected)
  36. {
  37. $jsonPath = new JSONPath($data);
  38. $result = $jsonPath->find($path)->data();
  39. $this->assertEquals($expected, $result);
  40. }
  41. }