File tree Expand file tree Collapse file tree 8 files changed +56
-1
lines changed
tests/functional/CSV/Safe Expand file tree Collapse file tree 8 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 5454 with :
5555 args : --prefer-dist
5656 php_version : 8.0
57-
57+ php_extensions : xdebug zip
5858 - name : PHPStan
5959 uses : php-actions/phpstan@v2
6060 with :
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ public function extract(): iterable
2727
2828 $ currentLine = $ this ->skipLines + 1 ;
2929
30+ $ columns = [];
31+ $ columnCount = 0 ;
32+ $ cellCount = 0 ;
33+
3034 /**
3135 * @var int $rowIndex
3236 * @var Row $row
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ public function __construct(
2525 $ this ->logger = $ logger ?? new NullLogger ();
2626 }
2727
28+ /**
29+ * @return \Generator
30+ */
2831 public function load (): \Generator
2932 {
3033 $ line = yield ;
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ public function extract(): iterable
2727
2828 $ currentLine = $ this ->skipLines + 1 ;
2929
30+ $ columns = [];
31+ $ columnCount = 0 ;
32+ $ cellCount = 0 ;
33+
3034 /**
3135 * @var int $rowIndex
3236 * @var Row $row
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ public function __construct(
2525 $ this ->logger = $ logger ?? new NullLogger ();
2626 }
2727
28+ /**
29+ * @return \Generator
30+ */
2831 public function load (): \Generator
2932 {
3033 $ line = yield ;
Original file line number Diff line number Diff line change @@ -24,13 +24,18 @@ public function __construct(
2424 private string $ sheetName ,
2525 ?LoggerInterface $ logger = null
2626 ) {
27+ /** @phpstan-ignore-next-line */
2728 $ this ->writer ->getCurrentSheet ()->setName ($ this ->sheetName );
2829 $ this ->logger = $ logger ?? new NullLogger ();
2930 }
3031
32+ /**
33+ * @return \Generator
34+ */
3135 public function load (): \Generator
3236 {
3337 $ line = yield ;
38+
3439 $ this ->writer ->addRow (
3540 new Row (array_map (fn ($ value ) => new Cell ($ value ), array_keys ($ line )), null )
3641 );
Original file line number Diff line number Diff line change @@ -24,10 +24,14 @@ public function __construct(
2424 private string $ sheetName ,
2525 ?LoggerInterface $ logger = null
2626 ) {
27+ /** @phpstan-ignore-next-line */
2728 $ this ->writer ->getCurrentSheet ()->setName ($ this ->sheetName );
2829 $ this ->logger = $ logger ?? new NullLogger ();
2930 }
3031
32+ /**
33+ * @return \Generator
34+ */
3135 public function load (): \Generator
3236 {
3337 $ line = yield ;
Original file line number Diff line number Diff line change 77use Kiboko \Component \PHPUnitExtension \PipelineAssertTrait ;
88use Kiboko \Component \Flow \Spreadsheet \CSV \Safe \Loader ;
99use PHPUnit \Framework \TestCase ;
10+ use Psr \Log \Test \TestLogger ;
1011use Vfs \FileSystem ;
1112
1213final class LoaderTest extends TestCase
@@ -60,4 +61,35 @@ public function testLoadCsvSuccessful()
6061 new Loader ($ this ->writer )
6162 );
6263 }
64+
65+ public function testLoadCsvWithLogger ()
66+ {
67+ $ this ->writer ->openToFile ('vfs://test.csv ' );
68+
69+ $ this ->assertPipelineLoadsLike (
70+ [
71+ [
72+ 'first name ' => 'john ' ,
73+ 'last name ' => 'doe ' ,
74+ ],
75+ [
76+ 'first name ' => 'jean ' ,
77+ 'last name ' => 'dupont ' ,
78+ ],
79+ ],
80+ [
81+ [
82+ 'first name ' => 'john ' ,
83+ 'last name ' => 'doe ' ,
84+ ],
85+ [
86+ 'first name ' => 'jean ' ,
87+ 'last name ' => 'dupont ' ,
88+ ],
89+ ],
90+ new Loader ($ this ->writer , new TestLogger ())
91+ );
92+
93+ $ this ->assertFileEquals (__DIR__ .'/../data/users.csv ' , 'vfs://test.csv ' );
94+ }
6395}
You can’t perform that action at this time.
0 commit comments