|
5 | 5 |
|
6 | 6 | use LargeArrayBuffer\LargeArrayBuffer; |
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | | -use PHPUnit\Framework\Attributes\DataProvider; |
9 | 8 |
|
10 | 9 | /** |
11 | 10 | * @author Andreas Wahlen |
@@ -77,7 +76,7 @@ public function testLoop(int $serializer, int $compression): void { |
77 | 76 | $count = 1500; |
78 | 77 | $buf = new LargeArrayBuffer(serializer: $serializer, compression: $compression); |
79 | 78 | $objs = []; |
80 | | - for($i=0;$i<$count;$i++){ |
| 79 | + for($i = 0; $i < $count; $i++){ |
81 | 80 | $o = new \stdClass(); |
82 | 81 | $o->idx = $i; |
83 | 82 | $objs[] = $o; |
@@ -107,4 +106,43 @@ public function testToJSON(): void { |
107 | 106 | fclose($stream); |
108 | 107 | $this->assertEquals(json_encode([$o, $o], JSON_THROW_ON_ERROR), $json); |
109 | 108 | } |
| 109 | + |
| 110 | + public function provideItems(): array { |
| 111 | + return [ |
| 112 | + [['hello world!', 'just another string']] |
| 113 | + ]; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @dataProvider provideItems |
| 118 | + */ |
| 119 | + public function testToArray(array $items): void { |
| 120 | + $buf = new LargeArrayBuffer(); |
| 121 | + foreach($items as $item){ |
| 122 | + $buf->push($item); |
| 123 | + } |
| 124 | + $this->assertSame($items, $buf->toArray()); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * @dataProvider provideItems |
| 129 | + */ |
| 130 | + public function testToFixedArray(array $items): void { |
| 131 | + $buf = new LargeArrayBuffer(); |
| 132 | + foreach($items as $item){ |
| 133 | + $buf->push($item); |
| 134 | + } |
| 135 | + $this->assertSame($items, $buf->toFixedArray()->toArray()); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @dataProvider provideItems |
| 140 | + */ |
| 141 | + public function testToGenerator(array $items): void { |
| 142 | + $buf = new LargeArrayBuffer(); |
| 143 | + foreach($items as $item){ |
| 144 | + $buf->push($item); |
| 145 | + } |
| 146 | + $this->assertSame($items, iterator_to_array($buf->toGenerator())); |
| 147 | + } |
110 | 148 | } |
0 commit comments