From 862da994a89ebaead679b61d3eee91e9dd62f168 Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 2 Jul 2024 12:03:14 +0200 Subject: [PATCH] Updated tests + fixed PhpStan errors --- src/Sheet/Safe/Loader.php | 6 +++++- tests/functional/Sheet/FingersCrossed/ExcelLoaderTest.php | 4 +++- .../Sheet/FingersCrossed/OpenDocumentLoaderTest.php | 4 +++- tests/functional/Sheet/Safe/ExcelLoaderTest.php | 4 +++- tests/functional/Sheet/Safe/OpenDocumentLoaderTest.php | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Sheet/Safe/Loader.php b/src/Sheet/Safe/Loader.php index 5822fed..386622e 100644 --- a/src/Sheet/Safe/Loader.php +++ b/src/Sheet/Safe/Loader.php @@ -10,6 +10,9 @@ use Box\Spout\Writer\Exception\WriterNotOpenedException; use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; +use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Contract\Bucket\ResultBucketInterface; +use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -24,7 +27,7 @@ public function __construct( public function load(): \Generator { - $line = yield; + $line = yield new EmptyResultBucket(); $headers = array_keys($line); try { $this->writer->addRow( @@ -36,6 +39,7 @@ public function load(): \Generator return; } + /* @phpstan-ignore-next-line */ while (true) { try { $this->writer->addRow($this->orderColumns($headers, $line)); diff --git a/tests/functional/Sheet/FingersCrossed/ExcelLoaderTest.php b/tests/functional/Sheet/FingersCrossed/ExcelLoaderTest.php index 49911a9..6369a08 100644 --- a/tests/functional/Sheet/FingersCrossed/ExcelLoaderTest.php +++ b/tests/functional/Sheet/FingersCrossed/ExcelLoaderTest.php @@ -74,9 +74,11 @@ public function load(): void 'last name' => 'dupont', ], ], - new Loader($this->writer, 'Sheet1') + new Loader($this->writer) ); + $this->writer->close(); + $this->assertRowWasWrittenToExcel( /* 'vfs://test.xlsx' */ $path, 'Sheet1', diff --git a/tests/functional/Sheet/FingersCrossed/OpenDocumentLoaderTest.php b/tests/functional/Sheet/FingersCrossed/OpenDocumentLoaderTest.php index 6794e82..16a7db9 100644 --- a/tests/functional/Sheet/FingersCrossed/OpenDocumentLoaderTest.php +++ b/tests/functional/Sheet/FingersCrossed/OpenDocumentLoaderTest.php @@ -74,9 +74,11 @@ public function load(): void 'last name' => 'dupont', ], ], - new Loader($this->writer, 'Sheet1') + new Loader($this->writer) ); + $this->writer->close(); + $this->assertRowWasWrittenToOpenDocument( /* 'vfs://test.ods' */ $path, 'Sheet1', diff --git a/tests/functional/Sheet/Safe/ExcelLoaderTest.php b/tests/functional/Sheet/Safe/ExcelLoaderTest.php index d794c4a..01255fc 100644 --- a/tests/functional/Sheet/Safe/ExcelLoaderTest.php +++ b/tests/functional/Sheet/Safe/ExcelLoaderTest.php @@ -74,9 +74,11 @@ public function load(): void 'last name' => 'dupont', ], ], - new Loader($this->writer, 'Sheet1') + new Loader($this->writer) ); + $this->writer->close(); + $this->assertRowWasWrittenToExcel( /* 'vfs://test.xlsx' */ $path, 'Sheet1', diff --git a/tests/functional/Sheet/Safe/OpenDocumentLoaderTest.php b/tests/functional/Sheet/Safe/OpenDocumentLoaderTest.php index 4b85834..ddb14d0 100644 --- a/tests/functional/Sheet/Safe/OpenDocumentLoaderTest.php +++ b/tests/functional/Sheet/Safe/OpenDocumentLoaderTest.php @@ -74,9 +74,11 @@ public function load(): void 'last name' => 'dupont', ], ], - new Loader($this->writer, 'Sheet1') + new Loader($this->writer) ); + $this->writer->close(); + $this->assertRowWasWrittenToOpenDocument( /* 'vfs://test.ods' */ $path, 'Sheet1',