From a73654cd65fb53a6350e5f682330dc91d818faea Mon Sep 17 00:00:00 2001 From: Filip Halaxa Date: Wed, 7 Nov 2018 19:37:19 +0100 Subject: [PATCH] Fixed double key yield --- src/Parser.php | 1 + test/JsonStreamReaderTest/ParserTest.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index f8eb6ae..30d9502 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -120,6 +120,7 @@ class Parser implements \IteratorAggregate $previousToken = null; if ($currentLevel === $iteratorLevel) { $key = $token; + $jsonBuffer = ''; } elseif ($currentLevel < $iteratorLevel) { $currentPath[$currentLevel] = json_decode($token); } diff --git a/test/JsonStreamReaderTest/ParserTest.php b/test/JsonStreamReaderTest/ParserTest.php index b901441..48caffa 100644 --- a/test/JsonStreamReaderTest/ParserTest.php +++ b/test/JsonStreamReaderTest/ParserTest.php @@ -15,8 +15,11 @@ class ParserTest extends \PHPUnit_Framework_TestCase */ public function testSyntax($pathSpec, $json, $expectedResult) { - $result = iterator_to_array($this->createParser($json, $pathSpec)); - $this->assertEquals($expectedResult, $result); + $resultWithKeys = iterator_to_array($this->createParser($json, $pathSpec)); + $resultNoKeys = iterator_to_array($this->createParser($json, $pathSpec), false); + + $this->assertEquals($expectedResult, $resultWithKeys); + $this->assertEquals(array_values($expectedResult), $resultNoKeys); } public function dataSyntax()