Chris@13: parse($code); Chris@13: $json = json_encode($stmts); Chris@13: Chris@13: $jsonDecoder = new JsonDecoder(); Chris@13: $decodedStmts = $jsonDecoder->decode($json); Chris@13: $this->assertEquals($stmts, $decodedStmts); Chris@13: } Chris@13: Chris@13: /** @dataProvider provideTestDecodingError */ Chris@13: public function testDecodingError($json, $expectedMessage) { Chris@13: $jsonDecoder = new JsonDecoder(); Chris@13: $this->expectException(\RuntimeException::class); Chris@13: $this->expectExceptionMessage($expectedMessage); Chris@13: $jsonDecoder->decode($json); Chris@13: } Chris@13: Chris@13: public function provideTestDecodingError() { Chris@13: return [ Chris@13: ['???', 'JSON decoding error: Syntax error'], Chris@13: ['{"nodeType":123}', 'Node type must be a string'], Chris@13: ['{"nodeType":"Name","attributes":123}', 'Attributes must be an array'], Chris@13: ['{"nodeType":"Comment"}', 'Comment must have text'], Chris@13: ['{"nodeType":"xxx"}', 'Unknown node type "xxx"'], Chris@13: ]; Chris@13: } Chris@13: }