forked from salsify/jsonstreamingparser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInMemoryListenerTest.php
More file actions
42 lines (36 loc) · 1.17 KB
/
InMemoryListenerTest.php
File metadata and controls
42 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace JsonStreamingParser\Test;
use JsonStreamingParser\Parser;
use JsonStreamingParser\Listener\InMemoryListener;
class InMemoryListenerTest extends \PHPUnit_Framework_TestCase
{
public function testExampleJson()
{
$testfile = dirname(__FILE__) . '/data/example.json';
$this->assertParsesCorrectly($testfile);
}
public function testGeoJson()
{
$testfile = dirname(__FILE__) . '/data/example.geojson';
$this->assertParsesCorrectly($testfile);
}
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->getJson();
// 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);
}
}