From 7ef46ab89b73a69ff804a721bc27509b3b8fa283 Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 30 Nov 2020 20:04:09 +0000 Subject: [PATCH 1/2] Apply PHP 8 compatibility changes --- system/I18n/Time.php | 2 +- system/Validation/Rules.php | 4 ++-- tests/system/Helpers/ArrayHelperTest.php | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/system/I18n/Time.php b/system/I18n/Time.php index 3ca8b676c097..4d7214fbb3c7 100644 --- a/system/I18n/Time.php +++ b/system/I18n/Time.php @@ -635,7 +635,7 @@ public function setYear($value) */ public function setMonth($value) { - if (is_numeric($value) && $value < 1 || $value > 12) + if (is_numeric($value) && ($value < 1 || $value > 12)) { throw I18nException::forInvalidMonth($value); } diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index b7a106770b59..51af179d9d68 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -274,7 +274,7 @@ public function matches(string $str = null, string $field, array $data): bool */ public function max_length(string $str = null, string $val): bool { - return ($val >= mb_strlen($str)); + return (is_numeric($val) && $val >= mb_strlen($str)); } //-------------------------------------------------------------------- @@ -289,7 +289,7 @@ public function max_length(string $str = null, string $val): bool */ public function min_length(string $str = null, string $val): bool { - return ($val <= mb_strlen($str)); + return (is_numeric($val) && $val <= mb_strlen($str)); } //-------------------------------------------------------------------- diff --git a/tests/system/Helpers/ArrayHelperTest.php b/tests/system/Helpers/ArrayHelperTest.php index cb0312a020b0..8d760203183c 100644 --- a/tests/system/Helpers/ArrayHelperTest.php +++ b/tests/system/Helpers/ArrayHelperTest.php @@ -219,8 +219,17 @@ public function testArraySortByMultipleKeysFailsEmptyParameter($data, $sortColum */ public function testArraySortByMultipleKeysFailsInconsistentArraySizes($data) { - $this->expectException('ErrorException'); - $this->expectExceptionMessage('Array sizes are inconsistent'); + // PHP 8 changes this error type + if (version_compare(PHP_VERSION, '8.0', '<')) + { + $this->expectException('ErrorException'); + $this->expectExceptionMessage('Array sizes are inconsistent'); + } + else + { + $this->expectException('ValueError'); + $this->expectExceptionMessage('Array sizes are inconsistent'); + } $sortColumns = [ 'team.orders' => SORT_ASC, From ffbe3184f5b160316fe3b5bbfc916f7cb120af1e Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 30 Nov 2020 15:57:17 -0500 Subject: [PATCH 2/2] Consolidate message Co-authored-by: Mostafa Khudair <59371810+mostafakhudair@users.noreply.github.com> --- tests/system/Helpers/ArrayHelperTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/Helpers/ArrayHelperTest.php b/tests/system/Helpers/ArrayHelperTest.php index 8d760203183c..ebdd5f1c3f1f 100644 --- a/tests/system/Helpers/ArrayHelperTest.php +++ b/tests/system/Helpers/ArrayHelperTest.php @@ -223,13 +223,13 @@ public function testArraySortByMultipleKeysFailsInconsistentArraySizes($data) if (version_compare(PHP_VERSION, '8.0', '<')) { $this->expectException('ErrorException'); - $this->expectExceptionMessage('Array sizes are inconsistent'); } else { - $this->expectException('ValueError'); - $this->expectExceptionMessage('Array sizes are inconsistent'); + $this->expectException('ValueError'); } + + $this->expectExceptionMessage('Array sizes are inconsistent'); $sortColumns = [ 'team.orders' => SORT_ASC,