json); $result = $jsonObject->get($jsonPath); $this->assertEquals([ [ [ 'track' => 'Simple Thing', 'stack' => 80 ], [ 'track' => 'Nobody', 'stack' => 90 ] ] ], $result ); $jsonPath = '$.music.bands[0].albums[0].length'; $result = $jsonObject->get($jsonPath); $this->assertEquals( [ '46:35' ], $result ); } /** * @throws InvalidJsonException */ public function testIntermediateLength() { $jsonPath = '$.music.length[0].track'; $jsonObject = new JsonObject($this->json); $result = $jsonObject->get($jsonPath); $this->assertEquals( [ 'Simple Thing' ], $result ); $jsonPath = '$.music.length[1].stack'; $result = $jsonObject->get($jsonPath); $this->assertEquals( [ 90 ], $result ); } /** * @throws InvalidJsonException */ public function testLength() { /** Array Length Test */ $jsonPath = '$.music.bands[0].albums.length'; $jsonObject = new JsonObject($this->json); $result = $jsonObject->get($jsonPath); $this->assertEquals( 3, $result ); /** String Length Test */ $jsonPath = '$.music.bands[0].albums[0].length.length'; $result = $jsonObject->get($jsonPath); $this->assertEquals( 5, $result ); $jsonPath = '$.music.bands[0].albums[1].title.length'; $result = $jsonObject->get($jsonPath); $this->assertEquals( 6, $result ); } /** * @throws InvalidJsonException */ public function testLengthSmartGet() { /** Array Length Test */ $jsonPath = '$.music.bands[0].albums.length'; $jsonObject = new JsonObject($this->json, true); $result = $jsonObject->get($jsonPath); $this->assertEquals( 3, $result ); /** String Length Test */ $jsonPath = '$.music.bands[0].albums[0].length.length'; $result = $jsonObject->get($jsonPath, true); $this->assertEquals( 5, $result ); $jsonPath = '$.music.bands[0].albums[1].title.length'; $result = $jsonObject->get($jsonPath, true); $this->assertEquals( 6, $result ); } /** * @throws InvalidJsonException */ public function testArrayLength() { /** Arrays Count Length Test */ $jsonPath = '$.music.bands[*].albums.length'; $jsonObject = new JsonObject($this->json); $result = $jsonObject->get($jsonPath); $this->assertEquals( [ 3, 3 ], $result ); /** String Length Test */ $jsonPath = '$.music.bands[0].albums[*].length.length'; $result = $jsonObject->get($jsonPath); $this->assertEquals( [ 5, 5, 6 ], $result ); $jsonPath = '$.music.bands[0].albums[*].title.length'; $result = $jsonObject->get($jsonPath); $this->assertEquals( [ 5, 6, 5 ], $result ); $jsonPath = '$.music.bands[*].albums[*].length.length'; $result = $jsonObject->get($jsonPath); $this->assertEquals( [ 5, 5, 6, 6, 6, 6 ], $result ); } }