-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallableSourceIteratorTest.php
More file actions
46 lines (40 loc) · 1.41 KB
/
CallableSourceIteratorTest.php
File metadata and controls
46 lines (40 loc) · 1.41 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
<?php
use Kriss\DataExporter\DataExporter;
use Kriss\DataExporter\Source\CallableSourceIterator;
use Sonata\Exporter\Source\ArraySourceIterator;
use Sonata\Exporter\Source\ChainSourceIterator;
it("CallableSourceIterator", function () {
$valueFromOuter = 'aaaa';
$source = new CallableSourceIterator(function () use (&$valueFromOuter) {
return new ArraySourceIterator([
[$valueFromOuter],
]);
});
$valueFromOuter = 'bbbb';
$filename = DataExporter::csv($source, [
'showHeaders' => false,
])->saveAs(__DIR__ . '/../tmp/test');
expect(strpos(file_get_contents($filename), $valueFromOuter) !== false)->toBeTrue();
});
it("CallableSourceIterator in Chain", function () {
$total = 0;
$source = new ChainSourceIterator([
new CallableSourceIterator(function () use (&$total) {
$arr = [];
for ($i = 0; $i < 100; $i++) {
$arr[] = ['x' . $i];
$total++;
}
return new ArraySourceIterator($arr);
}),
new CallableSourceIterator(function () use (&$total) {
return new ArraySourceIterator([
['total', $total],
]);
}),
]);
$filename = DataExporter::csv($source, [
'showHeaders' => false,
])->saveAs(__DIR__ . '/../tmp/test');
expect(strpos(file_get_contents($filename), '100') !== false)->toBeTrue();
});