forked from salsify/jsonstreamingparser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubsetConsumerTest.php
More file actions
63 lines (54 loc) · 1.61 KB
/
SubsetConsumerTest.php
File metadata and controls
63 lines (54 loc) · 1.61 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace JsonStreamingParser\Test;
use JsonStreamingParser\Parser;
use PHPUnit\Framework\TestCase;
class SubsetConsumerTest extends TestCase
{
public function testProposesAJsonSubsetToConsume(): void
{
$listener = new Listener\DatesRangeConsumer();
$parser = new Parser(fopen(__DIR__.'/data/dateRanges.json', 'rb'), $listener);
$parser->parse();
$this->assertSame(
[
[
'startDate' => '2013-10-24',
'endDate' => '2013-10-25',
], [
'startDate' => '2013-10-26',
'endDate' => '2013-10-27',
], [
'startDate' => '2013-11-01',
'endDate' => '2013-11-10',
],
],
$listener->dateRanges
);
}
/**
* @dataProvider differentJsonFiles
*
* @param string $fileToProcess
*/
public function testCollectsStructureCorrectly($fileToProcess): void
{
$listener = new Listener\IdealConsumer();
$parser = new Parser(fopen($fileToProcess, 'rb'), $listener);
$parser->parse();
$this->assertSame(
json_decode(file_get_contents($fileToProcess), true),
$listener->data
);
}
public static function differentJsonFiles()
{
$dataDir = __DIR__.'/data';
return [
[$dataDir.'/example.json'],
[$dataDir.'/plain.json'],
[$dataDir.'/dateRanges.json'],
[$dataDir.'/escapedChars.json'],
];
}
}