-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorChainSourceIteratorTest.php
More file actions
38 lines (33 loc) · 1.28 KB
/
GeneratorChainSourceIteratorTest.php
File metadata and controls
38 lines (33 loc) · 1.28 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
<?php
use Kriss\DataExporter\DataExporter;
use Kriss\DataExporter\Source\GeneratorChainSourceIterator;
use Sonata\Exporter\Source\ArraySourceIterator;
it("GeneratorChainSourceIterator", function () {
$source = new GeneratorChainSourceIterator(function () {
for ($i = 0; $i < 100; $i++) {
yield new ArraySourceIterator([
['a' . $i . '-1'],
['a' . $i . '-2'],
['a' . $i . '-3'],
]);
}
});
$filename = DataExporter::csv($source)->saveAs(__DIR__ . '/../tmp/test');
expect(count(file($filename)))->toBe(301);
});
it("GeneratorChainSourceIterator nesting", function () {
$source = new GeneratorChainSourceIterator(function () {
yield new GeneratorChainSourceIterator(function () {
yield new ArraySourceIterator([['a1']]);
yield new ArraySourceIterator([['a2']]);
});
yield new GeneratorChainSourceIterator(function () {
yield new ArraySourceIterator([['b1']]);
yield new GeneratorChainSourceIterator(function () {
yield new ArraySourceIterator([['c1']]);
});
});
});
$filename = DataExporter::csv($source)->saveAs(__DIR__ . '/../tmp/test');
expect(count(file($filename)))->toBe(5);
});