From f53b77a186cfffd3bb5dbe4e7822856d4a6c6cbb Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Thu, 27 Aug 2020 19:49:27 +0200 Subject: [PATCH] Add support for PHP 8.0 We already supported PHP 8.0 as our constrains in the "composer.json" file was ">=7.3", but we were not testing it before. Because of that, I found a bug on "EndsWith" which is fixed now. Signed-off-by: Henrique Moody --- .github/workflows/continuous-integration.yml | 5 ++++- composer.json | 2 +- library/Rules/EndsWith.php | 2 +- tests/integration/rules/resourceType.phpt | 4 ++-- tests/unit/Rules/CallableTypeTest.php | 7 ++++++- tests/unit/Rules/ResourceTypeTest.php | 13 ++++++++++++- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3ba8cf09..a59f1543 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,6 +21,9 @@ jobs: php-version: - "7.3" - "7.4" + include: + - php-version: "8.0" + composer-extra-arguments: --ignore-platform-reqs steps: - name: Checkout @@ -41,7 +44,7 @@ jobs: sudo locale-gen --no-purge --lang ru_RU.UTF-8 - name: Install dependencies - run: composer install --prefer-dist + run: composer install --prefer-dist ${{ matrix.composer-extra-arguments }} - name: Run unit tests run: vendor/bin/phpunit --testsuite=unit diff --git a/composer.json b/composer.json index 8656bcde..c63365de 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "sort-packages": true }, "require": { - "php": ">=7.3", + "php": "^7.3 || ^8.0", "respect/stringifier": "^0.2.0", "symfony/polyfill-mbstring": "^1.2" }, diff --git a/library/Rules/EndsWith.php b/library/Rules/EndsWith.php index 81775bfb..c0caf392 100644 --- a/library/Rules/EndsWith.php +++ b/library/Rules/EndsWith.php @@ -73,7 +73,7 @@ final class EndsWith extends AbstractRule $encoding = (string) mb_detect_encoding($input); $endPosition = mb_strlen($input, $encoding) - mb_strlen($this->endValue, $encoding); - return mb_strripos($input, $this->endValue, -1, $encoding) === $endPosition; + return mb_strripos($input, $this->endValue, 0, $encoding) === $endPosition; } /** diff --git a/tests/integration/rules/resourceType.phpt b/tests/integration/rules/resourceType.phpt index a35cbc44..ce906ebb 100644 --- a/tests/integration/rules/resourceType.phpt +++ b/tests/integration/rules/resourceType.phpt @@ -30,7 +30,7 @@ try { } try { - v::not(v::resourceType())->assert(xml_parser_create()); + v::not(v::resourceType())->assert(tmpfile()); } catch (NestedValidationException $exception) { echo $exception->getFullMessage() . PHP_EOL; } @@ -39,4 +39,4 @@ try { "test" must be a resource `[resource] (stream)` must not be a resource - `{ }` must be a resource -- `[resource] (xml)` must not be a resource +- `[resource] (stream)` must not be a resource diff --git a/tests/unit/Rules/CallableTypeTest.php b/tests/unit/Rules/CallableTypeTest.php index c3d8964f..86fa949f 100644 --- a/tests/unit/Rules/CallableTypeTest.php +++ b/tests/unit/Rules/CallableTypeTest.php @@ -42,7 +42,7 @@ final class CallableTypeTest extends RuleTestCase }, ], [$rule, 'trim'], - [$rule, __METHOD__], + [$rule, self::class . '::staticMethod'], [$rule, [$this, __FUNCTION__]], ]; } @@ -62,4 +62,9 @@ final class CallableTypeTest extends RuleTestCase [$rule, null], ]; } + + public static function staticMethod(): void + { + // This is a static method example + } } diff --git a/tests/unit/Rules/ResourceTypeTest.php b/tests/unit/Rules/ResourceTypeTest.php index 06cee8d4..44fef4b7 100644 --- a/tests/unit/Rules/ResourceTypeTest.php +++ b/tests/unit/Rules/ResourceTypeTest.php @@ -40,10 +40,21 @@ final class ResourceTypeTest extends RuleTestCase return [ [$rule, stream_context_create()], [$rule, tmpfile()], - [$rule, xml_parser_create()], ]; } + /** + * @test + * + * @requires PHP < 8.0 + */ + public function itShouldTestXmlResource(): void + { + $rule = new ResourceType(); + + self::assertValidInput($rule, xml_parser_create()); + } + /** * {@inheritDoc} */