From cc1020a611f2c2dd3a73bba6c34a55b91cdde723 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Fri, 17 Dec 2021 11:04:43 +0100 Subject: [PATCH] Add PHP 8.1 support, drop PHP 7.3 --- .github/workflows/phpunit.yml | 2 +- .gitignore | 1 + classes/PHPTAL.php | 2 +- classes/PHPTAL/DefaultKeyword.php | 2 + classes/PHPTAL/Dom/SaxXmlParser.php | 4 +- classes/PHPTAL/NothingKeyword.php | 2 + .../PHPTAL/Php/Attribute/I18N/Attributes.php | 2 +- classes/PHPTAL/Php/TalesInternal.php | 2 +- classes/PHPTAL/RepeatController.php | 5 + classes/PHPTAL/Tokenizer.php | 4 +- composer.json | 4 +- composer.lock | 121 +++++++++--------- phpunit.xml | 2 + tests/ArrayOverloadTest.php | 4 + tests/EchoExecuteTest.php | 2 +- tests/I18NDummyTranslator.php | 14 +- tests/TalConditionTest.php | 1 + tests/TalRepeatTest.php | 11 ++ 18 files changed, 110 insertions(+), 75 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index bb84ae6c..a17c52c6 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -17,9 +17,9 @@ jobs: - "highest" - "locked" php-version: - - "7.3" - "7.4" - "8.0" + - "8.1" operating-system: - "ubuntu-latest" diff --git a/.gitignore b/.gitignore index 53503623..7cc1232a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build /vendor/ /doc/temp/ /docs/ +.phpunit.result.cache diff --git a/classes/PHPTAL.php b/classes/PHPTAL.php index 26de8188..e00bac88 100644 --- a/classes/PHPTAL.php +++ b/classes/PHPTAL.php @@ -981,7 +981,7 @@ public function getFunctionName() if (!$this->_functionName) { // just to make tempalte name recognizable - $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath())); + $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath() ?? '')); $basename = substr(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $basename), "_"), 0, 20); $hash = md5(PHPTAL_VERSION . PHP_VERSION diff --git a/classes/PHPTAL/DefaultKeyword.php b/classes/PHPTAL/DefaultKeyword.php index 28d11e24..d16baa37 100644 --- a/classes/PHPTAL/DefaultKeyword.php +++ b/classes/PHPTAL/DefaultKeyword.php @@ -26,11 +26,13 @@ public function __toString() return "''"; } + #[\ReturnTypeWillChange] public function count() { return 1; } + #[\ReturnTypeWillChange] public function jsonSerialize() { return new stdClass; diff --git a/classes/PHPTAL/Dom/SaxXmlParser.php b/classes/PHPTAL/Dom/SaxXmlParser.php index 1aa7f1bb..76352767 100644 --- a/classes/PHPTAL/Dom/SaxXmlParser.php +++ b/classes/PHPTAL/Dom/SaxXmlParser.php @@ -370,7 +370,7 @@ private function checkEncoding($str) // $match expression below somehow triggers quite deep recurrency and stack overflow in preg // to avoid this, check string bit by bit, omitting ASCII fragments. if (strlen($str) > 200) { - $chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/',$str,null,PREG_SPLIT_NO_EMPTY); + $chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/',$str,0,PREG_SPLIT_NO_EMPTY); foreach ($chunks as $chunk) { if (strlen($chunk) < 200) { $this->checkEncoding($chunk); @@ -392,7 +392,7 @@ private function checkEncoding($str) . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'; // plane 16 if (!preg_match('/^(?:(?>'.$match.'))+$/s',$str)) { - $res = preg_split('/((?>'.$match.')+)/s',$str,null,PREG_SPLIT_DELIM_CAPTURE); + $res = preg_split('/((?>'.$match.')+)/s',$str,0,PREG_SPLIT_DELIM_CAPTURE); for($i=0; $i < count($res); $i+=2) { $res[$i] = self::convertBytesToEntities(array(1=>$res[$i])); diff --git a/classes/PHPTAL/NothingKeyword.php b/classes/PHPTAL/NothingKeyword.php index 22a79b0f..03d81649 100644 --- a/classes/PHPTAL/NothingKeyword.php +++ b/classes/PHPTAL/NothingKeyword.php @@ -26,11 +26,13 @@ public function __toString() return 'null'; } + #[\ReturnTypeWillChange] public function count() { return 0; } + #[\ReturnTypeWillChange] public function jsonSerialize() { return null; diff --git a/classes/PHPTAL/Php/Attribute/I18N/Attributes.php b/classes/PHPTAL/Php/Attribute/I18N/Attributes.php index 5eb3fac0..d4eb983c 100644 --- a/classes/PHPTAL/Php/Attribute/I18N/Attributes.php +++ b/classes/PHPTAL/Php/Attribute/I18N/Attributes.php @@ -68,7 +68,7 @@ public function before(PHPTAL_Php_CodeWriter $codewriter) list($qname, $key) = $this->parseSetExpression($exp); // if the translation key is specified and not empty (but may be '0') - if (strlen($key)) { + if ($key !== null && strlen($key) > 0) { // we use it and replace the tag attribute with the result of the translation $code = $this->_getTranslationCode($codewriter, $key); } else { diff --git a/classes/PHPTAL/Php/TalesInternal.php b/classes/PHPTAL/Php/TalesInternal.php index 4e84a660..f284ee2f 100644 --- a/classes/PHPTAL/Php/TalesInternal.php +++ b/classes/PHPTAL/Php/TalesInternal.php @@ -459,7 +459,7 @@ private static function convertExpressionsToExpression(array $array, $nothrow) */ public static function compileToPHPExpressions($expression, $nothrow=false) { - $expression = trim($expression); + $expression = trim($expression ?? ''); // Look for tales modifier (string:, exists:, Namespaced\Tale:, etc...) if (preg_match('/^([a-z](?:[a-z0-9._\\\\-]*[a-z0-9])?):(.*)$/si', $expression, $m)) { diff --git a/classes/PHPTAL/RepeatController.php b/classes/PHPTAL/RepeatController.php index 5d339140..c1f21fe0 100644 --- a/classes/PHPTAL/RepeatController.php +++ b/classes/PHPTAL/RepeatController.php @@ -87,6 +87,7 @@ public function __construct($source) * * @return Mixed The current element value */ + #[\ReturnTypeWillChange] public function current() { return $this->current; @@ -97,6 +98,7 @@ public function current() * * @return String/Int The current element key */ + #[\ReturnTypeWillChange] public function key() { return $this->key; @@ -107,6 +109,7 @@ public function key() * * @return bool True if the iteration is not finished yet */ + #[\ReturnTypeWillChange] public function valid() { $valid = $this->valid || $this->validOnNext; @@ -142,6 +145,7 @@ public function length() * Restarts the iteration process going back to the first element * */ + #[\ReturnTypeWillChange] public function rewind() { $this->index = 0; @@ -168,6 +172,7 @@ public function rewind() * Fetches the next element in the iteration and advances the pointer * */ + #[\ReturnTypeWillChange] public function next() { $this->index++; diff --git a/classes/PHPTAL/Tokenizer.php b/classes/PHPTAL/Tokenizer.php index 25ff3329..3d0ccbeb 100644 --- a/classes/PHPTAL/Tokenizer.php +++ b/classes/PHPTAL/Tokenizer.php @@ -47,7 +47,9 @@ function nextToken() } //if (!preg_match_all($this->regex, $this->str, $m, PREG_SET_ORDER, $this->offset)) throw new Exception("FAIL {$this->regex} at {$this->offset}"); - if (!preg_match($this->regex, $this->str, $m, null, $this->offset)) throw new Exception("FAIL {$this->regex} didn't match '{$this->str}' at {$this->offset}"); + if (!preg_match($this->regex, $this->str, $m, 0, $this->offset)) { + throw new Exception("FAIL {$this->regex} didn't match '{$this->str}' at {$this->offset}"); + } $this->offset += strlen($m[0]); // in bytes diff --git a/composer.json b/composer.json index a1e0b887..e037be34 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ } ], "require": { - "php": "^7.3 || ^8.0" + "php": "~7.4.0 || ~8.0.0 || ~8.1.0" }, "require-dev": { - "phpunit/phpunit": "^9.5.8" + "phpunit/phpunit": "^9.5.10" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index 3616fe4b..0f6d63f1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "646ca11c6768c05d7b723c0c3e7ec9eb", + "content-hash": "3bef1412b7acb31bae651440472bbc92", "packages": [], "packages-dev": [ { @@ -136,16 +136,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.12.0", + "version": "v4.13.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "6608f01670c3cc5079e18c1dab1104e002579143" + "reference": "210577fe3cf7badcc5814d99455df46564f3c077" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143", - "reference": "6608f01670c3cc5079e18c1dab1104e002579143", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077", + "reference": "210577fe3cf7badcc5814d99455df46564f3c077", "shasum": "" }, "require": { @@ -186,9 +186,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2" }, - "time": "2021-07-21T10:44:31+00:00" + "time": "2021-11-30T19:35:32+00:00" }, { "name": "phar-io/manifest", @@ -356,16 +356,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.2.2", + "version": "5.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", - "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", "shasum": "" }, "require": { @@ -376,7 +376,8 @@ "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2" + "mockery/mockery": "~1.3.2", + "psalm/phar": "^4.8" }, "type": "library", "extra": { @@ -406,22 +407,22 @@ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" }, - "time": "2020-09-03T19:13:55+00:00" + "time": "2021-10-19T17:43:47+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.4.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" + "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/a12f7e301eb7258bb68acd89d4aefa05c2906cae", + "reference": "a12f7e301eb7258bb68acd89d4aefa05c2906cae", "shasum": "" }, "require": { @@ -429,7 +430,8 @@ "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "*" + "ext-tokenizer": "*", + "psalm/phar": "^4.8" }, "type": "library", "extra": { @@ -455,39 +457,39 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.5.1" }, - "time": "2020-09-17T18:55:26+00:00" + "time": "2021-10-02T14:08:47+00:00" }, { "name": "phpspec/prophecy", - "version": "1.13.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.1", + "php": "^7.2 || ~8.0, <8.2", "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^6.0", + "phpspec/phpspec": "^6.0 || ^7.0", "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { @@ -522,29 +524,29 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.13.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.15.0" }, - "time": "2021-03-17T13:42:18+00:00" + "time": "2021-12-08T12:19:24+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.6", + "version": "9.2.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f6293e1b30a2354e8428e004689671b83871edde" + "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", - "reference": "f6293e1b30a2354e8428e004689671b83871edde", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687", + "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.10.2", + "nikic/php-parser": "^4.13.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -593,7 +595,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10" }, "funding": [ { @@ -601,20 +603,20 @@ "type": "github" } ], - "time": "2021-03-28T07:26:59+00:00" + "time": "2021-12-05T09:12:13+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.5", + "version": "3.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", "shasum": "" }, "require": { @@ -653,7 +655,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" }, "funding": [ { @@ -661,7 +663,7 @@ "type": "github" } ], - "time": "2020-09-28T05:57:25+00:00" + "time": "2021-12-02T12:48:52+00:00" }, { "name": "phpunit/php-invoker", @@ -846,16 +848,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.8", + "version": "9.5.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb" + "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb", - "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c814a05837f2edb0d1471d6e3f4ab3501ca3899a", + "reference": "c814a05837f2edb0d1471d6e3f4ab3501ca3899a", "shasum": "" }, "require": { @@ -871,7 +873,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.3", + "phpunit/php-code-coverage": "^9.2.7", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -933,7 +935,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.10" }, "funding": [ { @@ -945,7 +947,7 @@ "type": "github" } ], - "time": "2021-07-31T15:17:34+00:00" + "time": "2021-09-25T07:38:51+00:00" }, { "name": "sebastian/cli-parser", @@ -1376,16 +1378,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65" + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9", + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9", "shasum": "" }, "require": { @@ -1434,14 +1436,14 @@ } ], "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", + "homepage": "https://www.github.com/sebastianbergmann/exporter", "keywords": [ "export", "exporter" ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.4" }, "funding": [ { @@ -1449,7 +1451,7 @@ "type": "github" } ], - "time": "2020-09-28T05:24:23+00:00" + "time": "2021-11-11T14:18:36+00:00" }, { "name": "sebastian/global-state", @@ -1800,7 +1802,6 @@ "type": "github" } ], - "abandoned": true, "time": "2020-09-28T06:45:17+00:00" }, { @@ -2106,8 +2107,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.3 || ^8.0" + "php": "^7.4 || ^8.0" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } diff --git a/phpunit.xml b/phpunit.xml index 05a16bc0..31338a41 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,6 +2,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="./tests/config.php" + convertDeprecationsToExceptions="true" + colors="true" > diff --git a/tests/ArrayOverloadTest.php b/tests/ArrayOverloadTest.php index 66371802..a9652833 100644 --- a/tests/ArrayOverloadTest.php +++ b/tests/ArrayOverloadTest.php @@ -20,21 +20,25 @@ public function push($value) $this->_values[] = $value; } + #[\ReturnTypeWillChange] public function offsetGet($index) { return $this->_values[$index]; } + #[\ReturnTypeWillChange] public function offsetSet($index, $value) { $this->_values[$index] = $value; } + #[\ReturnTypeWillChange] public function offsetExists($of) { return isset($this->_values[$of]); } + #[\ReturnTypeWillChange] public function offsetUnset($of) { unset($this->_values[$of]); diff --git a/tests/EchoExecuteTest.php b/tests/EchoExecuteTest.php index 411197e1..00657acb 100644 --- a/tests/EchoExecuteTest.php +++ b/tests/EchoExecuteTest.php @@ -20,7 +20,7 @@ private function echoExecute(PHPTAL $tpl) { try { ob_start(); - $this->assertEquals(0, strlen($tpl->echoExecute())); + $this->assertEquals(0, strlen($tpl->echoExecute() ?? '')); $res = ob_get_clean(); } catch(Exception $e) { diff --git a/tests/I18NDummyTranslator.php b/tests/I18NDummyTranslator.php index 00bb860d..2fc77561 100644 --- a/tests/I18NDummyTranslator.php +++ b/tests/I18NDummyTranslator.php @@ -49,12 +49,16 @@ public function translate($key, $escape = true) $v = $key; } - if ($escape) $v = htmlspecialchars($v); + if ($escape && $v !== null) { + $v = htmlspecialchars($v); + } - while (preg_match('/\$\{(.*?)\}/sm', $v, $m)) { - list($src, $var) = $m; - if (!isset($this->vars[$var])) return "!*$var* is not defined!"; - $v = str_replace($src, $this->vars[$var], $v); + if ($v !== null) { + while (preg_match('/\$\{(.*?)\}/sm', $v, $m)) { + list($src, $var) = $m; + if (!isset($this->vars[$var])) return "!*$var* is not defined!"; + $v = str_replace($src, $this->vars[$var], $v); + } } diff --git a/tests/TalConditionTest.php b/tests/TalConditionTest.php index 67f78bb1..a1310024 100644 --- a/tests/TalConditionTest.php +++ b/tests/TalConditionTest.php @@ -191,6 +191,7 @@ function __construct($cnt=0) /** * @see Countable */ + #[\ReturnTypeWillChange] public function count() { return $this->cnt; } diff --git a/tests/TalRepeatTest.php b/tests/TalRepeatTest.php index 8075582c..d90c0b2f 100644 --- a/tests/TalRepeatTest.php +++ b/tests/TalRepeatTest.php @@ -337,26 +337,31 @@ function __construct($arr) if ($arr instanceof Iterator) $this->i = $arr; else $this->i = new ArrayIterator($arr); } + #[\ReturnTypeWillChange] function current() { $this->log .= "current\n"; return $this->i->current(); } + #[\ReturnTypeWillChange] function next() { $this->log .= "next\n"; return $this->i->next(); } + #[\ReturnTypeWillChange] function key() { $this->log .= "key\n"; return $this->i->key(); } + #[\ReturnTypeWillChange] function rewind() { $this->log .= "rewind\n"; return $this->i->rewind(); } + #[\ReturnTypeWillChange] function valid() { $this->log .= "valid\n"; @@ -376,23 +381,28 @@ public function __construct($size){ $this->_size= $size; } + #[\ReturnTypeWillChange] public function rewind(){ $this->_index = 0; } + #[\ReturnTypeWillChange] public function current(){ return $this->_index; } + #[\ReturnTypeWillChange] public function key(){ return $this->_index; } + #[\ReturnTypeWillChange] public function next(){ $this->_index++; return $this->_index; } + #[\ReturnTypeWillChange] public function valid(){ return $this->_index < $this->_size; } @@ -412,6 +422,7 @@ class SizeCalledException extends Exception {} class MyIterableThrowsOnSize extends MyIterable implements Countable { + #[\ReturnTypeWillChange] public function count() { throw new SizeCalledException("count() called");