From 260de6126c3acae99f1f821798a1aef5630a0764 Mon Sep 17 00:00:00 2001 From: Fonata Date: Mon, 26 Dec 2022 20:49:34 +0100 Subject: [PATCH] test: make code compatible with PHP 8 --- tests/methods/ParseTest.php | 12 +++++-- tests/properties/SortByTest.php | 56 +++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/tests/methods/ParseTest.php b/tests/methods/ParseTest.php index 22c8655..cf00fc8 100644 --- a/tests/methods/ParseTest.php +++ b/tests/methods/ParseTest.php @@ -87,7 +87,9 @@ class ParseTest extends TestCase { self::assertEquals(false, $this->csv->autoDetectionForDataString($sInput)); self::assertEquals(null, $this->csv->delimiter); $expected_data = explode("\r\n", $sInput); - $actual_data = array_map('reset', $this->csv->data); + $actual_data = array_map(function ($k) { + return reset($k); + }, $this->csv->data); self::assertEquals($expected_data, $actual_data); } @@ -98,7 +100,9 @@ class ParseTest extends TestCase { $expected_data = [86545235689, 34365587654, 13469874576]; $actual_data = $this->invokeMethod($this->csv, '_parse_string', [$sInput]); - $actual_column = array_map('reset', $actual_data); + $actual_column = array_map(function ($k) { + return reset($k); + }, $actual_data); self::assertEquals($expected_data, $actual_column); self::assertEquals( [ @@ -106,7 +110,9 @@ class ParseTest extends TestCase { 'b', "c\r\nd", ], - array_map('next', $actual_data) + array_map(function ($el) { + return next($el); + }, $actual_data) ); } diff --git a/tests/properties/SortByTest.php b/tests/properties/SortByTest.php index 58c0ef5..efdab03 100644 --- a/tests/properties/SortByTest.php +++ b/tests/properties/SortByTest.php @@ -7,26 +7,48 @@ class SortByTest extends BaseClass { public function testSortByRating() { $this->csv->sort_by = 'rating'; $this->csv->conditions = 'title does not contain Blood'; - $this->_compareWithExpected([ - // Rating 0 - 'The Killing Kind', - 'The Third Secret', + if (!preg_match('/^8\.2\./', phpversion())) + $this->_compareWithExpected([ + // Rating 0 + 'The Killing Kind', + 'The Third Secret', - // Rating 3 - 'The Last Templar', - 'The Broker (Paperback)', + // Rating 3 + 'The Last Templar', + 'The Broker (Paperback)', - // Rating 4 - 'Deception Point (Paperback)', - 'The Rule of Four (Paperback)', - 'The Da Vinci Code (Hardcover)', + // Rating 4 + 'Deception Point (Paperback)', + 'The Rule of Four (Paperback)', + 'The Da Vinci Code (Hardcover)', - // Rating 5 - 'State of Fear (Paperback)', - 'Prey', - 'Digital Fortress : A Thriller (Mass Market Paperback)', - 'Angels & Demons (Mass Market Paperback)', - ]); + // Rating 5 + 'State of Fear (Paperback)', + 'Prey', + 'Digital Fortress : A Thriller (Mass Market Paperback)', + 'Angels & Demons (Mass Market Paperback)', + ]); + else + $this->_compareWithExpected([ + // Rating 0 + 'The Killing Kind', + 'The Third Secret', + + // Rating 3 + 'The Last Templar', + 'The Broker (Paperback)', + + // Rating 4 + 'Deception Point (Paperback)', + 'The Rule of Four (Paperback)', + 'The Da Vinci Code (Hardcover)', + + // Rating 5 + 'Angels & Demons (Mass Market Paperback)', + 'State of Fear (Paperback)', + 'Prey', + 'Digital Fortress : A Thriller (Mass Market Paperback)', + ]); } public function testReverseSortByRating() {