forked from PHPOffice/PhpSpreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Method to Test Whether Csv Will Be Affected by Php9
See PHPOffice#4161. The best way to future-proof is to set the escape character to null string, and set testAutoDetect to false before reading. However, depending on the file being read, this may lead to different results than expected. This will be unavoidable because Php itself will change. This PR adds a new static method `affectedByPhp9` to Csv Reader. This can be used to identify in advance whether an input file will be affected by the changes. This will allow users to identify problems in advance, and prepare for how they might be handled.
- Loading branch information
Showing
6 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Csv; | ||
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Php9Test extends TestCase | ||
{ | ||
public function testAffectedByPhp9(): void | ||
{ | ||
if (PHP_VERSION_ID >= 90000) { | ||
$this->expectException(ReaderException::class); | ||
$this->expectExceptionMessage('Php7.4 or Php8'); | ||
} | ||
$dir = 'tests/data/Reader/CSV'; | ||
$files = glob("$dir/*"); | ||
self::assertNotFalse($files); | ||
$affected = []; | ||
foreach ($files as $file) { | ||
$base = basename($file); | ||
$encoding = 'UTF-8'; | ||
if (str_contains($base, 'utf') && !str_contains($base, 'bom')) { | ||
$encoding = 'guess'; | ||
} | ||
$result = Csv::affectedByPhp9($file, $encoding); | ||
if ($result) { | ||
$affected[] = $base; | ||
} | ||
} | ||
$expected = ['backslash.csv', 'escape.csv', 'linend.mac.csv']; | ||
self::assertSame($expected, $affected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A,12,3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
A,1 | ||
2,3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
A,1 | ||
2,3 |