Skip to content

Commit

Permalink
Improve internal codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Feb 25, 2023
1 parent 31da3d3 commit 39e8f36
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/AbstractCsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions src/CharsetConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/MapIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]);
}
}
10 changes: 4 additions & 6 deletions src/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39e8f36

Please sign in to comment.