-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceTest.php
More file actions
53 lines (42 loc) · 1.32 KB
/
SourceTest.php
File metadata and controls
53 lines (42 loc) · 1.32 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
<?php
use Kriss\DataExporter\DataExporter;
beforeEach(function () {
$this->filename = __DIR__ . '/../tmp/test';
});
it('Source array', function () {
$source = [
['a', 'b', 'c'],
['a', 'b', 'c'],
];
$filename = DataExporter::csv($source)->saveAs($this->filename);
expect(count(file($filename)))->toBe(3);
});
it('Source collection', function () {
$source = collect([
['a', 'b', 'c'],
['a', 'b', 'c'],
]);
$filename = DataExporter::csv($source)->saveAs($this->filename);
expect(count(file($filename)))->toBe(3);
});
it('Source generator', function () {
$source = (function () {
for ($i = 0; $i < 10; $i++) {
yield ['a' . $i];
}
})();
$filename = DataExporter::csv($source)->saveAs($this->filename);
expect(count(file($filename)))->toBe(11);
});
it('Source csv', function () {
$csvFilename = $this->filename . '-input.csv';
$fp = fopen($this->filename . '-input.csv', 'w');
fputcsv($fp, ['header1', 'header2']);
fputcsv($fp, ['aa', 'bb']);
fputcsv($fp, ['aa', 'bb']);
fputcsv($fp, ['aa', 'bb']);
fclose($fp);
$source = new \Sonata\Exporter\Source\CsvSourceIterator($csvFilename);
$filename = DataExporter::csv($source)->saveAs($this->filename);
expect(count(file($filename)))->toBe(4);
});