loadHTML($data['source']); $dom->documentURI = $data['uri']; return new MicrodataParser($dom); } /** * @dataProvider data */ public function testToObject($data) { $parser = $this->getParser($data); $result = $parser->toObject(); $this->assertEquals(json_decode($data['result']), $result); } /** * @dataProvider data */ public function testToArray($data) { $parser = $this->getParser($data); $result = $parser->toArray(); $this->assertEquals(json_decode($data['result'], true), $result); } /** * @dataProvider data */ public function testToJSON($data) { $parser = $this->getParser($data); $result = $parser->toJSON(); $this->assertJsonStringEqualsJsonString($data['result'], $result); } /** * @todo Provide more test data */ public function data() { return [ // https://www.w3.org/TR/microdata/#ex-jsonconv 'W3C Example' => [ $this->getTestData('W3C', 'source.html', 'result.json') ], 'Itemref & src based tags' => [ $this->getTestData('Itemref', 'source.html', 'result.json') ], ]; } private function getTestData($folderName, $sourceName, $resultName) { $folderPath = __DIR__.'/data/'.$folderName.'/'; $source = file_get_contents($folderPath . $sourceName); $result = file_get_contents($folderPath . $resultName); $uri = ''; // Set $uri if URI specified in test data if (preg_match('//', $source, $matches)) { $uri = $matches[1]; } return [ 'uri' => $uri, 'source' => $source, // HTML String 'result' => $result, // JSON String ]; } }