Skip to content

Commit

Permalink
Reduce Deprecation Warning in PHP8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 10, 2024
1 parent be9fef0 commit 730085f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ColumnConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected function setUp(): void
protected function tearDown(): void
{
$csv = new SplFileObject(__DIR__.'/../test_files/foo.csv', 'w');
$csv->setCsvControl();
$csv->fputcsv(['john', 'doe', '[email protected]'], ',', '"');
$csv->setCsvControl(escape: '\\');
$csv->fputcsv(fields: ['john', 'doe', '[email protected]']);
unset($this->csv);
}

Expand Down
2 changes: 1 addition & 1 deletion src/EscapeFormulaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testFormatterOnWriter(): void
$record = ['2', '2017-07-25', 'Important Client', '=2+5', 240, "\ttab", "\rcr", null];
$expected = "2,2017-07-25,\"Important Client\",'=2+5,240,\"'\ttab\",\"'\rcr\",\n";
$csv = Writer::createFromFileObject(new SplTempFileObject());
$csv->addFormatter(new EscapeFormula());
$csv->addFormatter((new EscapeFormula())->escapeRecord(...));
$csv->insertOne($record);
self::assertStringContainsString($expected, $csv->toString());
}
Expand Down
4 changes: 2 additions & 2 deletions src/InfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function testDetectDelimiterWithNoValidDelimiter(): void
public function testDetectDelimiterListWithInconsistentCSV(): void
{
$data = new SplTempFileObject();
$data->setCsvControl(';');
$data->setCsvControl(separator: ';', escape: '\\');
$data->fputcsv(['toto', 'tata', 'tutu']);
$data->setCsvControl('|');
$data->setCsvControl('|', escape: '\\');
$data->fputcsv(['toto', 'tata', 'tutu']);
$data->fputcsv(['toto', 'tata', 'tutu']);
$data->fputcsv(['toto', 'tata', 'tutu']);
Expand Down
9 changes: 6 additions & 3 deletions src/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class ReaderTest extends TabularDataReaderTestCase
protected function setUp(): void
{
$tmp = new SplTempFileObject();
$tmp->setCsvControl(escape: '\\');
foreach ($this->expected as $row) {
$tmp->fputcsv($row);
}
Expand Down Expand Up @@ -156,6 +157,7 @@ public function testCall(): void
];

$file = new SplTempFileObject();
$file->setCsvControl(escape: '\\');
foreach ($raw as $row) {
$file->fputcsv($row);
}
Expand Down Expand Up @@ -213,7 +215,7 @@ public function testStripBOM(array $record, string $expected_bom, string $expect
{
/** @var resource $fp */
$fp = fopen('php://temp', 'r+');
fputcsv($fp, $record);
fputcsv($fp, $record, escape: '');
$csv = Reader::createFromStream($fp);
self::assertSame($expected_bom, $csv->getInputBOM());
foreach ($csv as $row) {
Expand Down Expand Up @@ -274,7 +276,7 @@ public function testDisablingBOMStripping(): void
$expected_record = [Bom::Utf16Le->value.'john', 'doe', '[email protected]'];
/** @var resource $fp */
$fp = fopen('php://temp', 'r+');
fputcsv($fp, $expected_record);
fputcsv($fp, $expected_record, escape: '');
$csv = Reader::createFromStream($fp);
$csv->includeInputBOM();
self::assertSame(Bom::Utf16Le->value, $csv->getInputBOM());
Expand Down Expand Up @@ -333,7 +335,7 @@ public function testGetHeaderThrowsExceptionWithStreamObject(): void
/** @var resource $tmp */
$tmp = fopen('php://temp', 'r+');
foreach ($this->expected as $row) {
fputcsv($tmp, $row);
fputcsv($tmp, $row, escape: '');
}

$csv = Reader::createFromStream($tmp);
Expand Down Expand Up @@ -363,6 +365,7 @@ public function testJsonSerialize(): void
];

$tmp = new SplTempFileObject();
$tmp->setCsvControl(escape: '\\');
foreach ($expected as $row) {
$tmp->fputcsv($row);
}
Expand Down
5 changes: 5 additions & 0 deletions src/ResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class ResultSetTest extends TabularDataReaderTestCase
protected function setUp(): void
{
$tmp = new SplTempFileObject();
$tmp->setCsvControl(escape: '\\');
foreach ($this->expected as $row) {
$tmp->fputcsv($row);
}
Expand Down Expand Up @@ -173,6 +174,7 @@ public function testFetchAssocWithRowIndex(): void
];

$tmp = new SplTempFileObject();
$tmp->setCsvControl(escape: '\\');
foreach ($arr as $row) {
$tmp->fputcsv($row);
}
Expand Down Expand Up @@ -203,6 +205,7 @@ public function testFetchColumnInconsistentColumnCSV(): void
];

$file = new SplTempFileObject();
$file->setCsvControl(escape: '\\');
foreach ($raw as $row) {
$file->fputcsv($row);
}
Expand All @@ -220,6 +223,7 @@ public function testFetchColumnEmptyCol(): void
];

$file = new SplTempFileObject();
$file->setCsvControl(escape: '\\');
foreach ($raw as $row) {
$file->fputcsv($row);
}
Expand Down Expand Up @@ -312,6 +316,7 @@ public function testJsonSerialize(): void
];

$tmp = new SplTempFileObject();
$tmp->setCsvControl(escape: '\\');
foreach ($expected as $row) {
$tmp->fputcsv($row);
}
Expand Down
1 change: 1 addition & 0 deletions src/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class StatementTest extends TestCase
protected function setUp(): void
{
$tmp = new SplTempFileObject();
$tmp->setCsvControl(escape: '\\');
foreach ($this->expected as $row) {
$tmp->fputcsv($row);
}
Expand Down
4 changes: 2 additions & 2 deletions src/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testCreateStreamFromPathWithContext(): void
];

foreach ($expected as $row) {
fputcsv($fp, $row);
fputcsv($fp, $row, escape: '');
}

$stream = Stream::createFromPath(
Expand Down Expand Up @@ -143,7 +143,7 @@ public function testFSeekThrowsExceptionOnNonSeakableResource(): void
$this->expectException(UnavailableFeature::class);

$stream = Stream::createFromResource(STDOUT);
$stream->fputcsv(['foo', 'bar']);
$stream->fputcsv(['foo', 'bar'], escape: '');
$stream->fseek(-1);
}

Expand Down
4 changes: 2 additions & 2 deletions src/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected function setUp(): void
protected function tearDown(): void
{
$csv = new SplFileObject(__DIR__.'/../test_files/foo.csv', 'w');
$csv->setCsvControl();
$csv->fputcsv(['john', 'doe', '[email protected]'], ',', '"');
$csv->setCsvControl(escape: '');
$csv->fputcsv(['john', 'doe', '[email protected]']);
unset($this->csv);
}

Expand Down

0 comments on commit 730085f

Please sign in to comment.