decodeKey('"json"'); $valueResult = $decoder->decodeValue('"json"'); $this->assertTrue($keyResult->isOk()); $this->assertTrue($valueResult->isOk()); $this->assertEquals($case['wrappedDecodeValue'], $valueResult); $this->assertEquals($case['wrappedDecodeKey'], $keyResult); } public function data_testTrueFalseMatrix() { $notOkResult = new DecodingResult(false, null, 'Error happened.'); $okResult = new DecodingResult(true, 'json'); $wrappedNotOkResult = new DecodingResult(true, new DecodingError('"json"', 'Error happened.')); $wrappedOkResult = $okResult; return [ [ [ 'decodeValue' => $notOkResult, 'decodeKey' => $notOkResult, 'wrappedDecodeValue' => $wrappedNotOkResult, 'wrappedDecodeKey' => $wrappedNotOkResult, ] ], [ [ 'decodeValue' => $notOkResult, 'decodeKey' => $okResult, 'wrappedDecodeValue' => $wrappedNotOkResult, 'wrappedDecodeKey' => $wrappedOkResult, ] ], [ [ 'decodeValue' => $okResult, 'decodeKey' => $notOkResult, 'wrappedDecodeValue' => $wrappedOkResult, 'wrappedDecodeKey' => $wrappedNotOkResult, ] ], [ [ 'decodeValue' => $okResult, 'decodeKey' => $okResult, 'wrappedDecodeValue' => $wrappedOkResult, 'wrappedDecodeKey' => $wrappedOkResult, ] ], ]; } public function testCatchesErrorInsideIteratedJsonChunk() { $json = /** @lang JSON */ ' { "results": [ {"correct": "correct"}, {"incorrect": nulll}, {"correct": "correct"} ] } '; $items = Items::fromString($json, [ 'pointer' => '/results', 'decoder' => new ErrorWrappingDecoder(new ExtJsonDecoder(true)), ]); $result = iterator_to_array($items); $this->assertSame('correct', $result[0]['correct']); $this->assertSame('correct', $result[2]['correct']); /** @var DecodingError $decodingError */ $decodingError = $result[1]; $this->assertInstanceOf(DecodingError::class, $decodingError); $this->assertSame('{"incorrect":nulll}', $decodingError->getMalformedJson()); $this->assertSame('Syntax error', $decodingError->getErrorMessage()); } }