PHP Classes

File: tests/JSONPathDashedIndexTest.php

Recommend this page to a friend!
  Classes of Sascha Greuel   PHP JSON Path   tests/JSONPathDashedIndexTest.php   Download  
File: tests/JSONPathDashedIndexTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP JSON Path
Query values from data structures like XPATH
Author: By
Last change:
Date: 3 years ago
Size: 1,120 bytes
 

Contents

Class file image Download
<?php

/**
 * JSONPath implementation for PHP.
 *
 * @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
 */

declare(strict_types=1);

namespace
Flow\JSONPath\Test;

use
Flow\JSONPath\{JSONPath, JSONPathException};
use
PHPUnit\Framework\TestCase;

class
JSONPathDashedIndexTest extends TestCase
{
   
/**
     * @return array[]
     */
   
public function indexDataProvider(): array
    {
        return [
            [
               
'$.data[test-test-test]',
                [
'data' => ['test-test-test' => 'foo']],
                [
'foo'],
            ],
            [
               
'$.data[40f35757-2563-4790-b0b1-caa904be455f]',
                [
'data' => ['40f35757-2563-4790-b0b1-caa904be455f' => 'bar']],
                [
'bar'],
            ],
        ];
    }

   
/**
     * @dataProvider indexDataProvider
     *
     * @throws JSONPathException
     */
   
public function testSlice(string $path, array $data, array $expected): void
   
{
       
$results = (new JSONPath($data))
            ->
find($path);

       
self::assertEquals($expected, $results->getData());
    }
}