Skip to content

Commit a77cbc0

Browse files
committed
refactored
1 parent 0b18c36 commit a77cbc0

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/SimpleCsvFacade.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php namespace BayAreaWebPro\SimpleCsv;
22

3-
use Illuminate\Support\Facades\Facade as LaravelFacade;
3+
use Illuminate\Support\Collection;
44
use Illuminate\Support\LazyCollection;
5+
use Illuminate\Support\Facades\Facade as LaravelFacade;
56
/**
67
* The SimpleCsv Service Facade
7-
* @method static \Symfony\Component\HttpFoundation\StreamedResponse download(LazyCollection $collection, string $filename)
8-
* @method static void export(LazyCollection $collection, string $path)
8+
* @method static \Symfony\Component\HttpFoundation\StreamedResponse download(Collection|LazyCollection|\Iterator|\Generator|array $collection, string $filename)
9+
* @method static void export(Collection|LazyCollection|\Iterator|\Generator|array $collection, string $path)
910
* @method static LazyCollection import(string $path)
1011
*/
1112
class SimpleCsvFacade extends LaravelFacade

tests/Unit/DefaultTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Collection;
78
use Illuminate\Support\Str;
89
use Illuminate\Support\Facades\File;
910
use Illuminate\Support\LazyCollection;
@@ -57,6 +58,31 @@ private function getRandomStoragePath()
5758
return storage_path(Str::random(16) . '.csv');
5859
}
5960

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+
6086
public function test_export_files_and_restore()
6187
{
6288
$items = $this->getCollectionData()->toArray();

0 commit comments

Comments
 (0)