diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19bd4ce..b2b7f97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,19 +16,45 @@ jobs: strategy: fail-fast: false matrix: - php: [ - 7.1, - 7.2, - 7.3 - 7.4, - 8.0, - 8.1, - 8.2, - 8.3, - 8.4, - 8.5 - ] - composer: [basic] + # Keep the "modern" leg on PHPUnit 9 until the suite is upgraded for + # PHPUnit 10+, so CI currently stops at PHP 8.4. + include: + - php: '7.1' + composer: basic + phpunit: '^7.5' + phpunit_config: phpunit.legacy.xml.dist + - php: '7.2' + composer: basic + phpunit: '^8.5' + phpunit_config: phpunit.legacy.xml.dist + - php: '7.3' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist + - php: '7.4' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist + - php: '8.0' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist + - php: '8.1' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist + - php: '8.2' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist + - php: '8.3' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist + - php: '8.4' + composer: basic + phpunit: '^9.6' + phpunit_config: phpunit.xml.dist timeout-minutes: 10 steps: - name: Checkout code @@ -57,6 +83,7 @@ jobs: - name: Install dependencies run: | + composer require --dev --no-update "phpunit/phpunit:${{ matrix.phpunit }}" if [[ "${{ matrix.composer }}" == "lowest" ]]; then composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable fi; @@ -70,7 +97,7 @@ jobs: - name: Run tests run: | mkdir -p build/logs - XDEBUG_MODE=coverage php vendor/bin/phpunit -c phpunit.xml.dist + XDEBUG_MODE=coverage php vendor/bin/phpunit -c "${{ matrix.phpunit_config }}" - name: Run phpstan continue-on-error: true diff --git a/phpstan.neon b/phpstan.neon index a7a1e36..5e251e7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,14 @@ parameters: + # Analyze against the minimum supported runtime so PHP 7.1 compatibility + # issues are caught even when phpstan itself runs on a newer PHP in CI. + phpVersion: 70100 level: 8 paths: - %currentWorkingDirectory%/src/ + excludePaths: + # This file is only loaded on PHP 8.1+ by JsonSerializableReturnTypeTrait.php. + # It defines the same trait name, so excluding it prevents a duplicate-symbol error. + - %currentWorkingDirectory%/src/JsonSerializableReturnTypeTraitPhp81.php reportUnmatchedIgnoredErrors: false ignoreErrors: # false-positive? diff --git a/phpunit.legacy.xml.dist b/phpunit.legacy.xml.dist new file mode 100644 index 0000000..f6faeb7 --- /dev/null +++ b/phpunit.legacy.xml.dist @@ -0,0 +1,21 @@ + + + + + ./src/ + + + ./src/JsonSerializableReturnTypeTraitPhp81.php + + + + + + + + + tests + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cddd6d0..308ffc2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,6 +4,11 @@ ./src/ + + + ./src/JsonSerializableReturnTypeTraitPhp81.php + diff --git a/src/JsonSerializableReturnTypeTrait.php b/src/JsonSerializableReturnTypeTrait.php new file mode 100644 index 0000000..b42d8ca --- /dev/null +++ b/src/JsonSerializableReturnTypeTrait.php @@ -0,0 +1,24 @@ + $replacements = [], ?string $encoding = null) * @method static Stringy stripeCssMediaQueries(string $stringInput) * @method static Stringy stripeEmptyHtmlTags(string $stringInput) * @method static Stringy utf8ify(string $stringInput) diff --git a/src/Stringy.php b/src/Stringy.php index f7b600b..776e726 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -33,6 +33,8 @@ */ class Stringy implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonSerializable { + use JsonSerializableReturnTypeTrait; + /** * An instance's string. * @@ -2503,21 +2505,6 @@ public function isWhitespace(): bool return $this->isBlank(); } - /** - * Returns value which can be serialized by json_encode(). - * - * EXAMPLE: - * - * - * @psalm-mutation-free - * - * @return string The current value of the $str property - */ - public function jsonSerialize(): mixed - { - return (string) $this; - } - /** * Convert the string to kebab-case. * @@ -4988,6 +4975,8 @@ public function urlEncodeRaw(): self * @return static *

Object whose $str has been converted to an URL slug.

* + * @phpstan-param ASCII::*_LANGUAGE_CODE $language + * * @psalm-suppress ImpureMethodCall :/ */ public function urlify( diff --git a/tests/StringyStrictTest.php b/tests/StringyStrictTest.php index 5708beb..08fb531 100644 --- a/tests/StringyStrictTest.php +++ b/tests/StringyStrictTest.php @@ -1909,7 +1909,11 @@ public function testAppendRandomStringProducesCorrectChars() { $result = S::create('')->appendRandomString(8, 'abc'); static::assertSame(8, $result->length()); - static::assertMatchesRegularExpression('/^[abc]{8}$/', $result->toString()); + if (\method_exists(__CLASS__, 'assertMatchesRegularExpression')) { + static::assertMatchesRegularExpression('/^[abc]{8}$/', $result->toString()); + } else { + static::assertRegExp('/^[abc]{8}$/', $result->toString()); + } } public function testAddUniqueIdentifier() diff --git a/tests/StringyTest.php b/tests/StringyTest.php index 3081551..04232ea 100644 --- a/tests/StringyTest.php +++ b/tests/StringyTest.php @@ -1907,7 +1907,11 @@ public function testAppendRandomStringProducesCorrectChars() { $result = S::create('')->appendRandomString(8, 'abc'); static::assertSame(8, $result->length()); - static::assertMatchesRegularExpression('/^[abc]{8}$/', $result->toString()); + if (\method_exists(__CLASS__, 'assertMatchesRegularExpression')) { + static::assertMatchesRegularExpression('/^[abc]{8}$/', $result->toString()); + } else { + static::assertRegExp('/^[abc]{8}$/', $result->toString()); + } } public function testAddUniqueIdentifier()