@@ -16,36 +16,68 @@ final class NdJsonTest extends TestCase
1616 public function testReadStreamYieldsEventLines (): void
1717 {
1818 $ json1 = json_encode ([
19- 'type ' => 'event1 ' ,
19+ 'type ' => 'row ' ,
2020 'payload ' => [
2121 'foo ' => 'bar ' ,
2222 ],
2323 ]) . "\n" ;
2424 $ json2 = json_encode ([
25- 'type ' => 'event2 ' ,
25+ 'type ' => 'row ' ,
2626 'payload ' => [
2727 'baz ' => 'qux ' ,
2828 ],
2929 ]) . "\n" ;
30+ $ json3 = json_encode ([
31+ 'type ' => 'row ' ,
32+ 'payload ' => 'io.test.v1 ' ,
33+ ]) . "\n" ;
34+ $ json4 = json_encode ([
35+ 'type ' => 'row ' ,
36+ 'payload ' => 4 ,
37+ ]) . "\n" ;
38+ $ json5 = json_encode ([
39+ 'type ' => 'row ' ,
40+ 'payload ' => 1.2 ,
41+ ]) . "\n" ;
42+ $ json6 = json_encode ([
43+ 'type ' => 'row ' ,
44+ 'payload ' => true ,
45+ ]) . "\n" ;
3046
3147 $ stream = $ this ->createMock (Stream::class);
3248 $ stream ->method ('getIterator ' )
33- ->willReturn (new ArrayIterator ([$ json1 , $ json2 ]));
49+ ->willReturn (new ArrayIterator ([$ json1 , $ json2, $ json3 , $ json4 , $ json5 , $ json6 ]));
3450
3551 $ events = iterator_to_array (NdJson::readStream ($ stream ));
3652
37- $ this ->assertCount (2 , $ events );
53+ $ this ->assertCount (6 , $ events );
3854 $ this ->assertInstanceOf (ReadEventLine::class, $ events [0 ]);
39- $ this ->assertSame ('event1 ' , $ events [0 ]->type );
55+ $ this ->assertSame ('row ' , $ events [0 ]->type );
4056 $ this ->assertSame ([
4157 'foo ' => 'bar ' ,
4258 ], $ events [0 ]->payload );
4359
4460 $ this ->assertInstanceOf (ReadEventLine::class, $ events [1 ]);
45- $ this ->assertSame ('event2 ' , $ events [1 ]->type );
61+ $ this ->assertSame ('row ' , $ events [1 ]->type );
4662 $ this ->assertSame ([
4763 'baz ' => 'qux ' ,
4864 ], $ events [1 ]->payload );
65+
66+ $ this ->assertInstanceOf (ReadEventLine::class, $ events [2 ]);
67+ $ this ->assertSame ('row ' , $ events [2 ]->type );
68+ $ this ->assertSame ('io.test.v1 ' , $ events [2 ]->payload );
69+
70+ $ this ->assertInstanceOf (ReadEventLine::class, $ events [3 ]);
71+ $ this ->assertSame ('row ' , $ events [3 ]->type );
72+ $ this ->assertSame (4 , $ events [3 ]->payload );
73+
74+ $ this ->assertInstanceOf (ReadEventLine::class, $ events [4 ]);
75+ $ this ->assertSame ('row ' , $ events [4 ]->type );
76+ $ this ->assertEqualsWithDelta (1.2 , $ events [4 ]->payload , PHP_FLOAT_EPSILON );
77+
78+ $ this ->assertInstanceOf (ReadEventLine::class, $ events [5 ]);
79+ $ this ->assertSame ('row ' , $ events [5 ]->type );
80+ $ this ->assertTrue ($ events [5 ]->payload );
4981 }
5082
5183 public function testReadStreamSkipsEmptyLines (): void
0 commit comments