diff --git a/src/AbstractCsvTest.php b/src/AbstractCsvTest.php index 836dcb5a..c452e0b8 100644 --- a/src/AbstractCsvTest.php +++ b/src/AbstractCsvTest.php @@ -313,8 +313,9 @@ public function testFailedAddStreamFilterWithWrongFilter(): void /** @var resource $tmpfile */ $tmpfile = tmpfile(); - $csv = Writer::createFromStream($tmpfile); - $csv->addStreamFilter('foobar.toupper'); + + Writer::createFromStream($tmpfile) + ->addStreamFilter('foobar.toupper'); } public function testStreamFilterDetection(): void diff --git a/src/CharsetConverterTest.php b/src/CharsetConverterTest.php index 61278821..4c99b06d 100644 --- a/src/CharsetConverterTest.php +++ b/src/CharsetConverterTest.php @@ -65,10 +65,7 @@ public function testCharsetConverterConvertsAnArray(): void ->outputEncoding('utf-8') ; - /** @var array $result */ - $result = $converter->convert([$raw]); - - self::assertSame($expected, $result[0]); + self::assertSame($expected, [...$converter->convert([$raw])][0]); } public function testCharsetConverterConvertsAnIterator(): void @@ -125,10 +122,8 @@ public function testConvertOnlyStringField(array $record, array $expected): void $converter = (new CharsetConverter()) ->inputEncoding('iso-8859-15') ->outputEncoding('utf-8'); - /** @var array $res */ - $res = $converter->convert([$record]); - self::assertSame($expected, $res[0]); + self::assertSame($expected, [...$converter->convert([$record])][0]); } public static function converterProvider(): array diff --git a/src/MapIteratorTest.php b/src/MapIteratorTest.php index 54425fc0..a211a0bc 100644 --- a/src/MapIteratorTest.php +++ b/src/MapIteratorTest.php @@ -17,7 +17,6 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use function array_map; -use function iterator_to_array; #[Group('csv')] final class MapIteratorTest extends TestCase @@ -43,9 +42,6 @@ public function testMapIteratorCanAccessTheIteratorKey(): void $iterator = new ArrayIterator(['foo' => 'bar', 'bar' => 'baz']); $mapper = fn (string $value, $offset): string => $offset.' => '.$value; - self::assertSame( - $expected, - iterator_to_array(new MapIterator($iterator, $mapper), true) - ); + self::assertSame($expected, [...new MapIterator($iterator, $mapper)]); } } diff --git a/src/ReaderTest.php b/src/ReaderTest.php index 989b48a4..f006cb3d 100644 --- a/src/ReaderTest.php +++ b/src/ReaderTest.php @@ -23,7 +23,6 @@ use function fclose; use function fopen; use function fputcsv; -use function iterator_to_array; use function json_encode; use function unlink; @@ -159,11 +158,10 @@ public function testHeaderThrowsExceptionOnError(): void ); $csv->setHeaderOffset(0); self::assertSame(['field1', 'field1', 'field3'], $csv->getHeader()); - try { - iterator_to_array($csv); - } catch (SyntaxError $exception) { - self::assertSame(['field1'], $exception->duplicateColumnNames()); - } + + $this->expectExceptionObject(SyntaxError::dueToDuplicateHeaderColumnNames(['field1'])); + + [...$csv]; } public function testHeaderThrowsExceptionOnEmptyLine(): void