|
4 | 4 |
|
5 | 5 |
|
6 | 6 | use Illuminate\Database\Eloquent\Model;
|
| 7 | +use Illuminate\Support\Collection; |
7 | 8 | use Illuminate\Support\Str;
|
8 | 9 | use Illuminate\Support\Facades\File;
|
9 | 10 | use Illuminate\Support\LazyCollection;
|
@@ -57,6 +58,31 @@ private function getRandomStoragePath()
|
57 | 58 | return storage_path(Str::random(16) . '.csv');
|
58 | 59 | }
|
59 | 60 |
|
| 61 | + public function test_export_from_iterables() |
| 62 | + { |
| 63 | + $items = $this->getCollectionData(10)->toArray(); |
| 64 | + |
| 65 | + // Array |
| 66 | + $pathA = $this->getRandomStoragePath(); |
| 67 | + SimpleCsv::export($items, $pathA); |
| 68 | + |
| 69 | + $this->assertFileExists($pathA); |
| 70 | + $fileData = File::get($pathA); |
| 71 | + foreach ($items as $item) { |
| 72 | + $this->assertStringContainsString($item['email'], $fileData); |
| 73 | + } |
| 74 | + |
| 75 | + // Collection |
| 76 | + $pathB = $this->getRandomStoragePath(); |
| 77 | + SimpleCsv::export(Collection::make($items), $pathB); |
| 78 | + |
| 79 | + $this->assertFileExists($pathB); |
| 80 | + $fileData = File::get($pathB); |
| 81 | + foreach ($items as $item) { |
| 82 | + $this->assertStringContainsString($item['email'], $fileData); |
| 83 | + } |
| 84 | + } |
| 85 | + |
60 | 86 | public function test_export_files_and_restore()
|
61 | 87 | {
|
62 | 88 | $items = $this->getCollectionData()->toArray();
|
|
0 commit comments