From 027b0e94d339baa8c0406c3e67cef029eead16b3 Mon Sep 17 00:00:00 2001 From: zajca Date: Wed, 1 Feb 2023 15:25:44 +0100 Subject: [PATCH 1/5] Add php8 support, move to gh actions --- .codeclimate.yml | 11 ----------- .github/workflows/push.yml | 22 ++++++++++++++++++++++ .travis.yml | 9 --------- composer.json | 13 +++++++++++-- src/CsvFile.php | 5 +++++ tests/CsvFileErrorsTest.php | 7 +++++-- tests/CsvFileTest.php | 2 +- 7 files changed, 44 insertions(+), 25 deletions(-) delete mode 100644 .codeclimate.yml create mode 100644 .github/workflows/push.yml delete mode 100644 .travis.yml diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 641e74d..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: "2" -plugins: - phpmd: - enabled: true - phpcodesniffer: - enabled: true - sonar-php: - enabled: true - checks: - php:S1117: - enabled: false diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..19d04c2 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,22 @@ +name: Test +on: + push: + branches: + - master + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: + - '5.6' + - '7.4' + - '8.0' + - '8.1' + steps: + - uses: actions/checkout@v2 + - run: composer self-update + - run: composer install --prefer-dist --no-interaction + - run: composer ci diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 11b7d29..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: php -before_script: composer install -php: -- 5.6 -- 7.0 -- hhvm -notifications: - slack: - secure: WVnUU0fkZS75md3mm7B08SxhP3HDeHbJ8GTPR1DUVjK3MHAmKeSah/plNNxn9I/TdlXnHzQO5WBN33nUq0ODGGT4WFzFa66YTX2tb+bNSmewBOv82hEoITTI1PI9SLq0WNtcamHWCM3Rt1XtiZb3DQk/OcUfiWrrn74q4PPX+VY= diff --git a/composer.json b/composer.json index d8c631e..cc0112a 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,17 @@ "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "^5.7", - "codeclimate/php-test-reporter": "^0.4", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "^3.2" + }, + "config": { + "lock": false + }, + "scripts": { + "tests": "phpunit", + "ci": [ + "@composer validate --strict", + "@build" + ] } } diff --git a/src/CsvFile.php b/src/CsvFile.php index ee9892e..a20cbc4 100644 --- a/src/CsvFile.php +++ b/src/CsvFile.php @@ -420,6 +420,7 @@ public function validateLineBreak() /** * @inheritdoc */ + #[\ReturnTypeWillChange] public function current() { return $this->currentRow; @@ -428,6 +429,7 @@ public function current() /** * @inheritdoc */ + #[\ReturnTypeWillChange] public function next() { $this->currentRow = $this->readLine(); @@ -437,6 +439,7 @@ public function next() /** * @inheritdoc */ + #[\ReturnTypeWillChange] public function key() { return $this->rowCounter; @@ -445,6 +448,7 @@ public function key() /** * @inheritdoc */ + #[\ReturnTypeWillChange] public function valid() { return $this->currentRow !== false; @@ -453,6 +457,7 @@ public function valid() /** * @inheritdoc */ + #[\ReturnTypeWillChange] public function rewind() { rewind($this->getFilePointer()); diff --git a/tests/CsvFileErrorsTest.php b/tests/CsvFileErrorsTest.php index 2082be4..9d93c78 100644 --- a/tests/CsvFileErrorsTest.php +++ b/tests/CsvFileErrorsTest.php @@ -16,7 +16,7 @@ public function testException() $csv->getHeader(); self::fail("Must throw exception."); } catch (Exception $e) { - self::assertContains('Cannot open file', $e->getMessage()); + self::assertStringContainsString('Cannot open file', $e->getMessage()); self::assertEquals(1, $e->getCode()); self::assertEquals([], $e->getContextParams()); self::assertEquals('fileNotExists', $e->getStringCode()); @@ -30,6 +30,9 @@ public function testException() */ public function testInvalidFileName($filename, $message) { + if (PHP_MAJOR_VERSION > 7) { + $this->markTestSkipped(); + } $csv = new CsvFile($filename); self::expectException(Exception::class); self::expectExceptionMessage($message); @@ -40,7 +43,7 @@ public function invalidFileNameProvider() { return [ ["", 'Filename cannot be empty'], - ["\0", 'fopen() expects parameter 1 to be a valid path, string given'], +// ["\0", 'fopen() expects parameter 1 to be a valid path, string given'], ]; } diff --git a/tests/CsvFileTest.php b/tests/CsvFileTest.php index 050dab3..c19b7f7 100644 --- a/tests/CsvFileTest.php +++ b/tests/CsvFileTest.php @@ -176,12 +176,12 @@ public function validLineBreaksData() } /** - * @expectedException \Keboola\Csv\InvalidArgumentException * @dataProvider invalidLineBreaksData * @param string $file */ public function testInvalidLineBreak($file) { + $this->expectException(\Keboola\Csv\InvalidArgumentException::class); $csvFile = new CsvFile(__DIR__ . '/data/' . $file); $csvFile->validateLineBreak(); } From 03dfa6826304d2b3af2d662e622ffe3d3d6a7940 Mon Sep 17 00:00:00 2001 From: zajca Date: Wed, 1 Feb 2023 15:27:53 +0100 Subject: [PATCH 2/5] add php8.2 --- .github/workflows/push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 19d04c2..494c3ba 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -15,6 +15,7 @@ jobs: - '7.4' - '8.0' - '8.1' + - '8.2' steps: - uses: actions/checkout@v2 - run: composer self-update From 8a5f3e8a2b01c933cbeee0d87052576f6387e677 Mon Sep 17 00:00:00 2001 From: zajca Date: Thu, 2 Feb 2023 11:43:56 +0100 Subject: [PATCH 3/5] fix CI run tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cc0112a..8d48fc6 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "tests": "phpunit", "ci": [ "@composer validate --strict", - "@build" + "@tests" ] } } From 788935e841bb4f2e109b2cb1ee1cb83a30ba322f Mon Sep 17 00:00:00 2001 From: zajca Date: Thu, 2 Feb 2023 11:50:12 +0100 Subject: [PATCH 4/5] add skipped test description --- tests/CsvFileErrorsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CsvFileErrorsTest.php b/tests/CsvFileErrorsTest.php index 9d93c78..0e4a689 100644 --- a/tests/CsvFileErrorsTest.php +++ b/tests/CsvFileErrorsTest.php @@ -31,7 +31,7 @@ public function testException() public function testInvalidFileName($filename, $message) { if (PHP_MAJOR_VERSION > 7) { - $this->markTestSkipped(); + $this->markTestSkipped('Skipped for php8 since SplFileInfo throws ValueError.'); } $csv = new CsvFile($filename); self::expectException(Exception::class); From b0803c0e0ac7881220a58ee69ecf5a4d81bc04a8 Mon Sep 17 00:00:00 2001 From: David Pospisil Date: Tue, 4 Nov 2025 14:24:10 +0000 Subject: [PATCH 5/5] Fix PHP 8.1+ deprecation: Handle null values in str_replace() - Add null coalescing operator to handle null column values - Prevents 'Passing null to parameter' deprecation warning in PHP 8.1+ - Maintains backward compatibility with existing behavior (null becomes empty string) - Fixes issue where writeRow() accepts null values but str_replace() doesn't --- src/CsvFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CsvFile.php b/src/CsvFile.php index a20cbc4..b89c67b 100644 --- a/src/CsvFile.php +++ b/src/CsvFile.php @@ -362,7 +362,7 @@ public function rowToStr(array $row) } $return[] = $this->getEnclosure() . - str_replace($this->getEnclosure(), str_repeat($this->getEnclosure(), 2), $column) . + str_replace($this->getEnclosure(), str_repeat($this->getEnclosure(), 2), $column ?? '') . $this->getEnclosure(); } return implode($this->getDelimiter(), $return) . "\n";