private function assertParsesCorrectly($testfile)
 {
     // Parse using an InMemoryListener instance
     $listener = new InMemoryListener();
     $stream = fopen($testfile, 'r');
     try {
         $parser = new Parser($stream, $listener);
         $parser->parse();
         fclose($stream);
     } catch (Exception $e) {
         fclose($stream);
         throw $e;
     }
     $actual = $listener->get_json();
     // Parse using json_decode
     $expected = json_decode(file_get_contents($testfile), true);
     // Make sure the two produce the same object structure
     $this->assertSame($expected, $actual);
 }
Ejemplo n.º 2
0
<?php

require_once dirname(__FILE__) . '/../src/JsonStreamingParser/Parser.php';
require_once dirname(__FILE__) . '/InMemoryListener.php';
$testfile = dirname(__FILE__) . '/example.json';
$listener = new InMemoryListener();
$stream = fopen($testfile, 'r');
try {
    $parser = new JsonStreamingParser_Parser($stream, $listener);
    $parser->parse();
} catch (Exception $e) {
    fclose($stream);
    throw $e;
}
var_dump($listener->get_json());