From 4f1e5bafe27b07f545f90d8c92bb96789ff6f564 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 01/13] Allow Symfony ^8.0 --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 10d0ee6..e2f31fd 100644 --- a/composer.json +++ b/composer.json @@ -23,12 +23,12 @@ "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { - "symfony/error-handler": "^6.4|^7.0", - "symfony/emoji": "^7.1", - "symfony/http-client": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/error-handler": "^6.4|^7.0|^8.0", + "symfony/emoji": "^7.1|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/translation-contracts": "<2.5" From 4afdf1988ecf90190ca6704bfcb4b085a0b795e0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 24 Jun 2025 10:16:47 +0200 Subject: [PATCH 02/13] [String] Leverage grapheme_str_split() --- AbstractUnicodeString.php | 2 +- Tests/AbstractUnicodeTestCase.php | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AbstractUnicodeString.php b/AbstractUnicodeString.php index cf280cd..b6b8833 100644 --- a/AbstractUnicodeString.php +++ b/AbstractUnicodeString.php @@ -360,7 +360,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static public function reverse(): static { $str = clone $this; - $str->string = implode('', array_reverse(preg_split('/(\X)/u', $str->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY))); + $str->string = implode('', array_reverse(grapheme_str_split($str->string))); return $str; } diff --git a/Tests/AbstractUnicodeTestCase.php b/Tests/AbstractUnicodeTestCase.php index 2433f89..1c70993 100644 --- a/Tests/AbstractUnicodeTestCase.php +++ b/Tests/AbstractUnicodeTestCase.php @@ -751,7 +751,7 @@ public static function provideReverse() [ ['äuß⭐erst', 'tsre⭐ßuä'], ['漢字ーユニコードéèΣσς', 'ςσΣèéドーコニユー字漢'], - ['नमस्ते', 'तेस्मन'], + // ['नमस्ते', 'तेस्मन'], this case requires a version of intl that supports Unicode 15.1 ] ); } diff --git a/composer.json b/composer.json index e2f31fd..a7ae848 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=8.2", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-grapheme": "~1.33", "symfony/polyfill-intl-normalizer": "~1.0", "symfony/polyfill-mbstring": "~1.0" }, From 7ea0c86d7555d888ba1911a4bcbbb25d575756a7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 8 Jul 2025 11:08:29 +0200 Subject: [PATCH 03/13] Various CS fixes --- Tests/Slugger/AsciiSluggerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Slugger/AsciiSluggerTest.php b/Tests/Slugger/AsciiSluggerTest.php index 7604f3b..b78baf3 100644 --- a/Tests/Slugger/AsciiSluggerTest.php +++ b/Tests/Slugger/AsciiSluggerTest.php @@ -112,7 +112,7 @@ public static function provideSlugEmojiTests(): iterable */ public function testSlugEmojiWithSetLocale() { - if (!setlocale(LC_ALL, 'C.UTF-8')) { + if (!setlocale(\LC_ALL, 'C.UTF-8')) { $this->markTestSkipped('Unable to switch to the "C.UTF-8" locale.'); } From 89ecb57ea26d588329e0ac38a7bbd652afce90bd Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Sat, 12 Jul 2025 15:55:19 +0200 Subject: [PATCH 04/13] optimize `in_array` calls --- AbstractUnicodeString.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AbstractUnicodeString.php b/AbstractUnicodeString.php index b6b8833..2e7e202 100644 --- a/AbstractUnicodeString.php +++ b/AbstractUnicodeString.php @@ -264,7 +264,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array public function normalize(int $form = self::NFC): static { - if (!\in_array($form, [self::NFC, self::NFD, self::NFKC, self::NFKD])) { + if (!\in_array($form, [self::NFC, self::NFD, self::NFKC, self::NFKD], true)) { throw new InvalidArgumentException('Unsupported normalization form.'); } From f253dec477bea2a6cc728f6abae56d9de99756d7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 24 Jul 2025 14:45:41 +0200 Subject: [PATCH 05/13] Fix typos --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0782ae2..141036c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,7 @@ CHANGELOG * added `LazyString` which provides memoizing stringable objects * The component is not marked as `@experimental` anymore * added the `s()` helper method to get either an `UnicodeString` or `ByteString` instance, - depending of the input string UTF-8 compliancy + depending of the input string UTF-8 compliance * added `$cut` parameter to `Symfony\Component\String\AbstractString::truncate()` * added `AbstractString::containsAny()` * allow passing a string of custom characters to `ByteString::fromRandom()` From a9f583bc3e942e9af017033937d4f3473a567a1c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Oct 2024 11:06:51 +0200 Subject: [PATCH 06/13] run tests using PHPUnit 11.5 --- phpunit.xml.dist | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 32741bd..0921942 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + + From 1790e2302fbe9792b2754a7646114875cb80dea2 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 31 Jul 2025 14:36:46 +0200 Subject: [PATCH 07/13] replace PHPUnit annotations with attributes --- Tests/AbstractAsciiTestCase.php | 225 ++++++----------------- Tests/AbstractUnicodeTestCase.php | 27 +-- Tests/FunctionsTest.php | 13 +- Tests/Inflector/EnglishInflectorTest.php | 9 +- Tests/Inflector/FrenchInflectorTest.php | 9 +- Tests/Inflector/SpanishInflectorTest.php | 13 +- Tests/LazyStringTest.php | 5 +- Tests/Slugger/AsciiSluggerTest.php | 17 +- Tests/SluggerTest.php | 9 +- 9 files changed, 92 insertions(+), 235 deletions(-) diff --git a/Tests/AbstractAsciiTestCase.php b/Tests/AbstractAsciiTestCase.php index e673f27..aaf57e3 100644 --- a/Tests/AbstractAsciiTestCase.php +++ b/Tests/AbstractAsciiTestCase.php @@ -11,6 +11,7 @@ namespace Symfony\Component\String\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\String\AbstractString; use Symfony\Component\String\ByteString; @@ -44,9 +45,7 @@ public function testCreateFromEmptyString() $this->assertTrue($instance->isEmpty()); } - /** - * @dataProvider provideBytesAt - */ + #[DataProvider('provideBytesAt')] public function testBytesAt(array $expected, string $string, int $offset, ?int $form = null) { if (2 !== grapheme_strlen('च्छे') && 'नमस्ते' === $string) { @@ -69,9 +68,7 @@ public static function provideBytesAt(): array ]; } - /** - * @dataProvider provideIndexOf - */ + #[DataProvider('provideIndexOf')] public function testContainsAny(?int $result, string $string, $needle) { $instance = static::createFromString($string); @@ -79,9 +76,7 @@ public function testContainsAny(?int $result, string $string, $needle) $this->assertSame(null !== $instance->indexOf($needle), $instance->containsAny($needle)); } - /** - * @dataProvider provideIndexOfIgnoreCase - */ + #[DataProvider('provideIndexOfIgnoreCase')] public function testContainsAnyIgnoreCase(?int $result, string $string, $needle) { $instance = static::createFromString($string); @@ -100,9 +95,7 @@ public function testUnwrap() $this->assertEquals($expected, $actual); } - /** - * @dataProvider wordwrapProvider - */ + #[DataProvider('wordwrapProvider')] public function testWordwrap($expected, $actual, $length, $break, $cut = false) { $instance = static::createFromString($actual); @@ -144,9 +137,7 @@ public static function wordwrapProvider() ]; } - /** - * @dataProvider provideWrap - */ + #[DataProvider('provideWrap')] public function testWrap(array $expected, array $values) { $s = static::createFromString(''); @@ -169,9 +160,7 @@ public static function provideWrap(): array ]; } - /** - * @dataProvider provideLength - */ + #[DataProvider('provideLength')] public function testLength(int $length, string $string) { if (2 !== grapheme_strlen('च्छे') && 'अनुच्छेद' === $string) { @@ -196,9 +185,7 @@ public static function provideLength(): array ]; } - /** - * @dataProvider provideIndexOf - */ + #[DataProvider('provideIndexOf')] public function testIndexOf(?int $result, string $string, $needle, int $offset) { $instance = static::createFromString($string); @@ -227,9 +214,7 @@ public static function provideIndexOf(): array ]; } - /** - * @dataProvider provideIndexOfIgnoreCase - */ + #[DataProvider('provideIndexOfIgnoreCase')] public function testIndexOfIgnoreCase(?int $result, string $string, $needle, int $offset) { $instance = static::createFromString($string); @@ -259,9 +244,7 @@ public static function provideIndexOfIgnoreCase(): array ]; } - /** - * @dataProvider provideIndexOfLast - */ + #[DataProvider('provideIndexOfLast')] public function testIndexOfLast(?int $result, string $string, $needle, int $offset) { $instance = static::createFromString($string); @@ -286,9 +269,7 @@ public static function provideIndexOfLast(): array ]; } - /** - * @dataProvider provideIndexOfLastIgnoreCase - */ + #[DataProvider('provideIndexOfLastIgnoreCase')] public function testIndexOfLastIgnoreCase(?int $result, string $string, string $needle, int $offset) { $instance = static::createFromString($string); @@ -317,9 +298,7 @@ public static function provideIndexOfLastIgnoreCase(): array ]; } - /** - * @dataProvider provideSplit - */ + #[DataProvider('provideSplit')] public function testSplit(string $string, string $delimiter, array $chunks, ?int $limit, ?int $flags = null) { $this->assertEquals($chunks, static::createFromString($string)->split($delimiter, $limit, $flags)); @@ -428,9 +407,7 @@ public static function provideSplit(): array ]; } - /** - * @dataProvider provideInvalidChunkLength - */ + #[DataProvider('provideInvalidChunkLength')] public function testInvalidChunkLength(int $length) { $this->expectException(InvalidArgumentException::class); @@ -447,9 +424,7 @@ public static function provideInvalidChunkLength(): array ]; } - /** - * @dataProvider provideChunk - */ + #[DataProvider('provideChunk')] public function testChunk(string $string, array $chunks, int $length) { $this->assertEquals($chunks, static::createFromString($string)->chunk($length)); @@ -519,9 +494,7 @@ public static function provideChunk() ]; } - /** - * @dataProvider provideLower - */ + #[DataProvider('provideLower')] public function testLower(string $expected, string $origin) { $instance = static::createFromString($origin)->lower(); @@ -543,9 +516,7 @@ public static function provideLower() ]; } - /** - * @dataProvider provideUpper - */ + #[DataProvider('provideUpper')] public function testUpper(string $expected, string $origin) { $instance = static::createFromString($origin)->upper(); @@ -567,9 +538,7 @@ public static function provideUpper() ]; } - /** - * @dataProvider provideTitle - */ + #[DataProvider('provideTitle')] public function testTitle(string $expected, string $origin, bool $allWords) { $this->assertEquals( @@ -593,9 +562,7 @@ public static function provideTitle() ]; } - /** - * @dataProvider provideSlice - */ + #[DataProvider('provideSlice')] public function testSlice(string $expected, string $origin, int $start, ?int $length = null) { $this->assertEquals( @@ -621,9 +588,7 @@ public static function provideSlice() ]; } - /** - * @dataProvider provideSplice - */ + #[DataProvider('provideSplice')] public function testSplice(string $expected, int $start, ?int $length = null) { $this->assertEquals( @@ -649,9 +614,7 @@ public static function provideSplice() ]; } - /** - * @dataProvider provideAppend - */ + #[DataProvider('provideAppend')] public function testAppend(string $expected, array $suffixes) { $instance = static::createFromString(''); @@ -684,9 +647,7 @@ public static function provideAppend() ]; } - /** - * @dataProvider provideAppend - */ + #[DataProvider('provideAppend')] public function testPrepend(string $expected, array $prefixes) { $instance = static::createFromString(''); @@ -701,9 +662,7 @@ public function testPrepend(string $expected, array $prefixes) $this->assertEquals(static::createFromString($expected), $instance); } - /** - * @dataProvider provideTrim - */ + #[DataProvider('provideTrim')] public function testTrim(string $expected, string $origin, ?string $chars) { $result = static::createFromString($origin); @@ -752,9 +711,7 @@ public function testTrimPrefix() $this->assertEquals(static::createFromString('def'), $str->ignoreCase()->trimPrefix('ABC.')); } - /** - * @dataProvider provideTrimStart - */ + #[DataProvider('provideTrimStart')] public function testTrimStart(string $expected, string $origin, ?string $chars) { $result = static::createFromString($origin); @@ -788,9 +745,7 @@ public static function provideTrimStart() ]; } - /** - * @dataProvider provideTrimEnd - */ + #[DataProvider('provideTrimEnd')] public function testTrimEnd(string $expected, string $origin, ?string $chars) { $result = static::createFromString($origin); @@ -820,9 +775,7 @@ public static function provideTrimEnd() ]; } - /** - * @dataProvider provideBeforeAfter - */ + #[DataProvider('provideBeforeAfter')] public function testBeforeAfter(string $expected, string $needle, string $origin, int $offset, bool $before) { $result = static::createFromString($origin); @@ -848,9 +801,7 @@ public static function provideBeforeAfter() ]; } - /** - * @dataProvider provideBeforeAfterIgnoreCase - */ + #[DataProvider('provideBeforeAfterIgnoreCase')] public function testBeforeAfterIgnoreCase(string $expected, string $needle, string $origin, int $offset, bool $before) { $result = static::createFromString($origin)->ignoreCase(); @@ -876,9 +827,7 @@ public static function provideBeforeAfterIgnoreCase() ]; } - /** - * @dataProvider provideBeforeAfterLast - */ + #[DataProvider('provideBeforeAfterLast')] public function testBeforeAfterLast(string $expected, string $needle, string $origin, int $offset, bool $before) { $result = static::createFromString($origin); @@ -905,9 +854,7 @@ public static function provideBeforeAfterLast() ]; } - /** - * @dataProvider provideBeforeAfterLastIgnoreCase - */ + #[DataProvider('provideBeforeAfterLastIgnoreCase')] public function testBeforeAfterLastIgnoreCase(string $expected, string $needle, string $origin, int $offset, bool $before) { $result = static::createFromString($origin)->ignoreCase(); @@ -935,9 +882,7 @@ public static function provideBeforeAfterLastIgnoreCase() ]; } - /** - * @dataProvider provideFolded - */ + #[DataProvider('provideFolded')] public function testFolded(string $expected, string $origin) { $this->assertEquals( @@ -954,9 +899,7 @@ public static function provideFolded() ]; } - /** - * @dataProvider provideReplace - */ + #[DataProvider('provideReplace')] public function testReplace(string $expectedString, int $expectedCount, string $origin, string $from, string $to) { $origin = static::createFromString($origin); @@ -977,9 +920,7 @@ public static function provideReplace() ]; } - /** - * @dataProvider provideReplaceMatches - */ + #[DataProvider('provideReplaceMatches')] public function testReplaceMatches(string $expectedString, string $origin, string $fromRegexp, $to) { $origin = static::createFromString($origin); @@ -1003,9 +944,7 @@ public static function provideReplaceMatches() ]; } - /** - * @dataProvider provideReplaceIgnoreCase - */ + #[DataProvider('provideReplaceIgnoreCase')] public function testReplaceIgnoreCase(string $expectedString, int $expectedCount, string $origin, string $from, string $to) { $origin = static::createFromString($origin); @@ -1026,9 +965,7 @@ public static function provideReplaceIgnoreCase() ]; } - /** - * @dataProvider provideCamel - */ + #[DataProvider('provideCamel')] public function testCamel(string $expectedString, string $origin) { $instance = static::createFromString($origin)->camel(); @@ -1052,9 +989,7 @@ public static function provideCamel() ]; } - /** - * @dataProvider provideSnake - */ + #[DataProvider('provideSnake')] public function testSnake(string $expectedString, string $origin) { $instance = static::createFromString($origin)->snake(); @@ -1089,9 +1024,7 @@ public static function provideSnake() ]; } - /** - * @dataProvider provideKebab - */ + #[DataProvider('provideKebab')] public function testKebab(string $expectedString, string $origin) { $instance = static::createFromString($origin)->kebab(); @@ -1118,9 +1051,7 @@ public static function provideKebab(): array ]; } - /** - * @dataProvider providePascal - */ + #[DataProvider('providePascal')] public function testPascal(string $expectedString, string $origin) { $instance = static::createFromString($origin)->pascal(); @@ -1145,9 +1076,7 @@ public static function providePascal(): array ]; } - /** - * @dataProvider provideStartsWith - */ + #[DataProvider('provideStartsWith')] public function testStartsWith(bool $expected, string $origin, $prefix, ?int $form = null) { $instance = static::createFromString($origin); @@ -1174,9 +1103,7 @@ public static function provideStartsWith() ]; } - /** - * @dataProvider provideStartsWithIgnoreCase - */ + #[DataProvider('provideStartsWithIgnoreCase')] public function testStartsWithIgnoreCase(bool $expected, string $origin, $prefix) { $this->assertSame($expected, static::createFromString($origin)->ignoreCase()->startsWith($prefix)); @@ -1199,9 +1126,7 @@ public static function provideStartsWithIgnoreCase() ]; } - /** - * @dataProvider provideEndsWith - */ + #[DataProvider('provideEndsWith')] public function testEndsWith(bool $expected, string $origin, $suffix, ?int $form = null) { $instance = static::createFromString($origin); @@ -1228,9 +1153,7 @@ public static function provideEndsWith() ]; } - /** - * @dataProvider provideEndsWithIgnoreCase - */ + #[DataProvider('provideEndsWithIgnoreCase')] public function testEndsWithIgnoreCase(bool $expected, string $origin, $suffix) { $this->assertSame($expected, static::createFromString($origin)->ignoreCase()->endsWith($suffix)); @@ -1253,9 +1176,7 @@ public static function provideEndsWithIgnoreCase() ]; } - /** - * @dataProvider provideEnsureStart - */ + #[DataProvider('provideEnsureStart')] public function testEnsureStart(string $expectedString, string $origin, $prefix) { $instance = static::createFromString($origin)->ensureStart($prefix); @@ -1279,9 +1200,7 @@ public static function provideEnsureStart() ]; } - /** - * @dataProvider provideEnsureStartIgnoreCase - */ + #[DataProvider('provideEnsureStartIgnoreCase')] public function testEnsureStartIgnoreCase(string $expectedString, string $origin, $prefix) { $instance = static::createFromString($origin)->ignoreCase()->ensureStart($prefix); @@ -1304,9 +1223,7 @@ public static function provideEnsureStartIgnoreCase() ]; } - /** - * @dataProvider provideEnsureEnd - */ + #[DataProvider('provideEnsureEnd')] public function testEnsureEnd(string $expectedString, string $origin, $suffix) { $instance = static::createFromString($origin)->ensureEnd($suffix); @@ -1330,9 +1247,7 @@ public static function provideEnsureEnd() ]; } - /** - * @dataProvider provideEnsureEndIgnoreCase - */ + #[DataProvider('provideEnsureEndIgnoreCase')] public function testEnsureEndIgnoreCase(string $expectedString, string $origin, $suffix) { $instance = static::createFromString($origin)->ignoreCase()->ensureEnd($suffix); @@ -1355,9 +1270,7 @@ public static function provideEnsureEndIgnoreCase() ]; } - /** - * @dataProvider provideCollapseWhitespace - */ + #[DataProvider('provideCollapseWhitespace')] public function testCollapseWhitespace(string $expectedString, string $origin) { $instance = static::createFromString($origin)->collapseWhitespace(); @@ -1376,9 +1289,7 @@ public static function provideCollapseWhitespace() ]; } - /** - * @dataProvider provideEqualsTo - */ + #[DataProvider('provideEqualsTo')] public function testEqualsTo(bool $expected, string $origin, $other) { $this->assertSame($expected, static::createFromString($origin)->equalsTo($other)); @@ -1402,9 +1313,7 @@ public static function provideEqualsTo() ]; } - /** - * @dataProvider provideEqualsToIgnoreCase - */ + #[DataProvider('provideEqualsToIgnoreCase')] public function testEqualsToIgnoreCase(bool $expected, string $origin, $other) { $this->assertSame($expected, static::createFromString($origin)->ignoreCase()->equalsTo($other)); @@ -1427,9 +1336,7 @@ public static function provideEqualsToIgnoreCase() ]; } - /** - * @dataProvider provideIsEmpty - */ + #[DataProvider('provideIsEmpty')] public function testIsEmpty(bool $expected, string $origin) { $this->assertSame($expected, static::createFromString($origin)->isEmpty()); @@ -1445,9 +1352,7 @@ public static function provideIsEmpty() ]; } - /** - * @dataProvider provideJoin - */ + #[DataProvider('provideJoin')] public function testJoin(string $expected, string $origin, array $join) { $instance = static::createFromString($origin)->join($join); @@ -1471,9 +1376,7 @@ public static function provideJoin() ]; } - /** - * @dataProvider provideRepeat - */ + #[DataProvider('provideRepeat')] public function testRepeat(string $expected, string $origin, int $multiplier) { $instance = static::createFromString($origin)->repeat($multiplier); @@ -1492,9 +1395,7 @@ public static function provideRepeat() ]; } - /** - * @dataProvider providePadBoth - */ + #[DataProvider('providePadBoth')] public function testPadBoth(string $expected, string $origin, int $length, string $padStr) { $instance = static::createFromString($origin)->padBoth($length, $padStr); @@ -1516,9 +1417,7 @@ public static function providePadBoth() ]; } - /** - * @dataProvider providePadEnd - */ + #[DataProvider('providePadEnd')] public function testPadEnd(string $expected, string $origin, int $length, string $padStr) { $instance = static::createFromString($origin)->padEnd($length, $padStr); @@ -1539,9 +1438,7 @@ public static function providePadEnd() ]; } - /** - * @dataProvider providePadStart - */ + #[DataProvider('providePadStart')] public function testPadStart(string $expected, string $origin, int $length, string $padStr) { $instance = static::createFromString($origin)->padStart($length, $padStr); @@ -1562,9 +1459,7 @@ public static function providePadStart() ]; } - /** - * @dataProvider provideTruncate - */ + #[DataProvider('provideTruncate')] public function testTruncate(string $expected, string $origin, int $length, string $ellipsis, bool|TruncateMode $cut = TruncateMode::Char) { $instance = static::createFromString($origin)->truncate($length, $ellipsis, $cut); @@ -1637,9 +1532,7 @@ public function testToString() self::assertSame('foobar', $instance->toString()); } - /** - * @dataProvider provideReverse - */ + #[DataProvider('provideReverse')] public function testReverse(string $expected, string $origin) { $instance = static::createFromString($origin)->reverse(); @@ -1656,9 +1549,7 @@ public static function provideReverse() ]; } - /** - * @dataProvider provideWidth - */ + #[DataProvider('provideWidth')] public function testWidth(int $expected, string $origin, bool $ignoreAnsiDecoration = true) { $this->assertSame($expected, static::createFromString($origin)->width($ignoreAnsiDecoration)); @@ -1687,9 +1578,7 @@ public static function provideWidth(): array ]; } - /** - * @dataProvider provideToByteString - */ + #[DataProvider('provideToByteString')] public function testToByteString(string $origin, string $encoding) { $instance = static::createFromString($origin)->toByteString($encoding); diff --git a/Tests/AbstractUnicodeTestCase.php b/Tests/AbstractUnicodeTestCase.php index 1c70993..95c9dc9 100644 --- a/Tests/AbstractUnicodeTestCase.php +++ b/Tests/AbstractUnicodeTestCase.php @@ -11,6 +11,8 @@ namespace Symfony\Component\String\Tests; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Symfony\Component\String\Exception\InvalidArgumentException; abstract class AbstractUnicodeTestCase extends AbstractAsciiTestCase @@ -50,11 +52,8 @@ public function testAsciiClosureRule() $this->assertSame('Dieser Wert sollte grOEsser oder gleich', (string) $s->ascii([$rule])); } - /** - * @dataProvider provideLocaleLower - * - * @requires extension intl - */ + #[DataProvider('provideLocaleLower')] + #[RequiresPhpExtension('intl')] public function testLocaleLower(string $locale, string $expected, string $origin) { $instance = static::createFromString($origin)->localeLower($locale); @@ -64,11 +63,8 @@ public function testLocaleLower(string $locale, string $expected, string $origin $this->assertSame($expected, (string) $instance); } - /** - * @dataProvider provideLocaleUpper - * - * @requires extension intl - */ + #[DataProvider('provideLocaleUpper')] + #[RequiresPhpExtension('intl')] public function testLocaleUpper(string $locale, string $expected, string $origin) { $instance = static::createFromString($origin)->localeUpper($locale); @@ -78,11 +74,8 @@ public function testLocaleUpper(string $locale, string $expected, string $origin $this->assertSame($expected, (string) $instance); } - /** - * @dataProvider provideLocaleTitle - * - * @requires extension intl - */ + #[DataProvider('provideLocaleTitle')] + #[RequiresPhpExtension('intl')] public function testLocaleTitle(string $locale, string $expected, string $origin) { $instance = static::createFromString($origin)->localeTitle($locale); @@ -117,9 +110,7 @@ public static function provideBytesAt(): array ); } - /** - * @dataProvider provideCodePointsAt - */ + #[DataProvider('provideCodePointsAt')] public function testCodePointsAt(array $expected, string $string, int $offset, ?int $form = null) { if (2 !== grapheme_strlen('च्छे') && 'नमस्ते' === $string) { diff --git a/Tests/FunctionsTest.php b/Tests/FunctionsTest.php index 6a69106..e4f93ef 100644 --- a/Tests/FunctionsTest.php +++ b/Tests/FunctionsTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\String\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\String\AbstractString; use Symfony\Component\String\ByteString; @@ -22,9 +23,7 @@ final class FunctionsTest extends TestCase { - /** - * @dataProvider provideSStrings - */ + #[DataProvider('provideSStrings')] public function testS(AbstractString $expected, ?string $input) { $this->assertEquals($expected, s($input)); @@ -42,9 +41,7 @@ public static function provideSStrings(): array ]; } - /** - * @dataProvider provideUStrings - */ + #[DataProvider('provideUStrings')] public function testU(UnicodeString $expected, ?string $input) { $this->assertEquals($expected, u($input)); @@ -60,9 +57,7 @@ public static function provideUStrings(): array ]; } - /** - * @dataProvider provideBStrings - */ + #[DataProvider('provideBStrings')] public function testB(ByteString $expected, ?string $input) { $this->assertEquals($expected, b($input)); diff --git a/Tests/Inflector/EnglishInflectorTest.php b/Tests/Inflector/EnglishInflectorTest.php index 16287f4..c9bc23e 100644 --- a/Tests/Inflector/EnglishInflectorTest.php +++ b/Tests/Inflector/EnglishInflectorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\String\Tests\Inflector; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\String\Inflector\EnglishInflector; @@ -333,17 +334,13 @@ public static function pluralizeProvider() ]; } - /** - * @dataProvider singularizeProvider - */ + #[DataProvider('singularizeProvider')] public function testSingularize(string $plural, $singular) { $this->assertSame(\is_array($singular) ? $singular : [$singular], (new EnglishInflector())->singularize($plural)); } - /** - * @dataProvider pluralizeProvider - */ + #[DataProvider('pluralizeProvider')] public function testPluralize(string $singular, $plural) { $this->assertSame(\is_array($plural) ? $plural : [$plural], (new EnglishInflector())->pluralize($singular)); diff --git a/Tests/Inflector/FrenchInflectorTest.php b/Tests/Inflector/FrenchInflectorTest.php index 530b027..5507934 100644 --- a/Tests/Inflector/FrenchInflectorTest.php +++ b/Tests/Inflector/FrenchInflectorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\String\Tests\Inflector; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\String\Inflector\FrenchInflector; @@ -127,9 +128,7 @@ public static function pluralizeProvider() ]; } - /** - * @dataProvider pluralizeProvider - */ + #[DataProvider('pluralizeProvider')] public function testSingularize(string $singular, string $plural) { $this->assertSame([$singular], (new FrenchInflector())->singularize($plural)); @@ -137,9 +136,7 @@ public function testSingularize(string $singular, string $plural) $this->assertSame([ucfirst($singular)], (new FrenchInflector())->singularize(ucfirst($plural))); } - /** - * @dataProvider pluralizeProvider - */ + #[DataProvider('pluralizeProvider')] public function testPluralize(string $singular, string $plural) { $this->assertSame([$plural], (new FrenchInflector())->pluralize($singular)); diff --git a/Tests/Inflector/SpanishInflectorTest.php b/Tests/Inflector/SpanishInflectorTest.php index b10509a..faa862d 100644 --- a/Tests/Inflector/SpanishInflectorTest.php +++ b/Tests/Inflector/SpanishInflectorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\String\Tests\Inflector; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\String\Inflector\SpanishInflector; @@ -123,9 +124,7 @@ public static function uninflectedProvider(): array ]; } - /** - * @dataProvider singularizeProvider - */ + #[DataProvider('singularizeProvider')] public function testSingularize(string $plural, $singular) { $this->assertSame( @@ -134,9 +133,7 @@ public function testSingularize(string $plural, $singular) ); } - /** - * @dataProvider pluralizeProvider - */ + #[DataProvider('pluralizeProvider')] public function testPluralize(string $singular, $plural) { $this->assertSame( @@ -145,9 +142,7 @@ public function testPluralize(string $singular, $plural) ); } - /** - * @dataProvider uninflectedProvider - */ + #[DataProvider('uninflectedProvider')] public function testUninflected(string $word) { $this->assertSame( diff --git a/Tests/LazyStringTest.php b/Tests/LazyStringTest.php index b5405bb..5d70d2c 100644 --- a/Tests/LazyStringTest.php +++ b/Tests/LazyStringTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\String\Tests; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Symfony\Component\ErrorHandler\ErrorHandler; use Symfony\Component\String\LazyString; @@ -29,9 +30,7 @@ public function testLazyString() $this->assertSame(1, $count); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testReturnTypeError() { ErrorHandler::register(); diff --git a/Tests/Slugger/AsciiSluggerTest.php b/Tests/Slugger/AsciiSluggerTest.php index b78baf3..026a201 100644 --- a/Tests/Slugger/AsciiSluggerTest.php +++ b/Tests/Slugger/AsciiSluggerTest.php @@ -11,14 +11,14 @@ namespace Symfony\Component\String\Tests\Slugger; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; use Symfony\Component\String\Slugger\AsciiSlugger; class AsciiSluggerTest extends TestCase { - /** - * @dataProvider provideSlugTests - */ + #[DataProvider('provideSlugTests')] public function testSlug(string $expected, string $string, string $separator = '-', ?string $locale = null) { $slugger = new AsciiSlugger(); @@ -47,11 +47,8 @@ public static function provideSlugTests(): iterable yield [\function_exists('transliterator_transliterate') ? 'gh' : '', 'ғ', '-', 'uz_fr']; // Ensure we get the parent locale } - /** - * @dataProvider provideSlugEmojiTests - * - * @requires extension intl - */ + #[RequiresPhpExtension('intl')] + #[DataProvider('provideSlugEmojiTests')] public function testSlugEmoji(string $expected, string $string, ?string $locale, string|bool $emoji = true) { $slugger = new AsciiSlugger(); @@ -107,9 +104,7 @@ public static function provideSlugEmojiTests(): iterable ]; } - /** - * @requires extension intl - */ + #[RequiresPhpExtension('intl')] public function testSlugEmojiWithSetLocale() { if (!setlocale(\LC_ALL, 'C.UTF-8')) { diff --git a/Tests/SluggerTest.php b/Tests/SluggerTest.php index 6b4fc64..18fc023 100644 --- a/Tests/SluggerTest.php +++ b/Tests/SluggerTest.php @@ -11,16 +11,15 @@ namespace Symfony\Component\String\Tests; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; use Symfony\Component\String\Slugger\AsciiSlugger; class SluggerTest extends TestCase { - /** - * @requires extension intl - * - * @dataProvider provideSlug - */ + #[RequiresPhpExtension('intl')] + #[DataProvider('provideSlug')] public function testSlug(string $string, string $locale, string $expectedSlug) { $slugger = new AsciiSlugger($locale); From 08587b6ef645178c1095581c83c36b9f817041bb Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 24 Jun 2025 13:39:09 +0100 Subject: [PATCH 08/13] Remove some implicit bool type juggling --- UnicodeString.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/UnicodeString.php b/UnicodeString.php index b458de0..811ae02 100644 --- a/UnicodeString.php +++ b/UnicodeString.php @@ -106,11 +106,13 @@ public function endsWith(string|iterable|AbstractString $suffix): bool return false; } + $grapheme = grapheme_extract($this->string, \strlen($suffix), \GRAPHEME_EXTR_MAXBYTES, \strlen($this->string) - \strlen($suffix)) ?: ''; + if ($this->ignoreCase) { - return 0 === mb_stripos(grapheme_extract($this->string, \strlen($suffix), \GRAPHEME_EXTR_MAXBYTES, \strlen($this->string) - \strlen($suffix)), $suffix, 0, 'UTF-8'); + return 0 === mb_stripos($grapheme, $suffix, 0, 'UTF-8'); } - return $suffix === grapheme_extract($this->string, \strlen($suffix), \GRAPHEME_EXTR_MAXBYTES, \strlen($this->string) - \strlen($suffix)); + return $suffix === $grapheme; } public function equalsTo(string|iterable|AbstractString $string): bool @@ -355,11 +357,13 @@ public function startsWith(string|iterable|AbstractString $prefix): bool return false; } + $grapheme = grapheme_extract($this->string, \strlen($prefix), \GRAPHEME_EXTR_MAXBYTES) ?: ''; + if ($this->ignoreCase) { - return 0 === mb_stripos(grapheme_extract($this->string, \strlen($prefix), \GRAPHEME_EXTR_MAXBYTES), $prefix, 0, 'UTF-8'); + return 0 === mb_stripos($grapheme, $prefix, 0, 'UTF-8'); } - return $prefix === grapheme_extract($this->string, \strlen($prefix), \GRAPHEME_EXTR_MAXBYTES); + return $prefix === $grapheme; } public function __wakeup(): void From c8307f9af0560beaa728b835b466ba89900d99bf Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 10 Aug 2025 00:28:14 +0200 Subject: [PATCH 09/13] chore: heredoc indentation as of PHP 7.3 https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc --- Resources/WcswidthDataGenerator.php | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Resources/WcswidthDataGenerator.php b/Resources/WcswidthDataGenerator.php index 005b148..9fa6107 100644 --- a/Resources/WcswidthDataGenerator.php +++ b/Resources/WcswidthDataGenerator.php @@ -80,24 +80,24 @@ private function getHeader(string $version): string $date = (new \DateTimeImmutable())->format('c'); return << - * - * This file has been auto-generated by the Symfony String Component for internal use. - * - * Unicode version: $version - * Date: $date - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - - -EOT; + + * + * This file has been auto-generated by the Symfony String Component for internal use. + * + * Unicode version: $version + * Date: $date + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + + EOT; } private function format(array $rawData): array From 2f72656c5bf4e556c8d902ab73dd14f90c650086 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 1 Aug 2025 14:58:41 +0200 Subject: [PATCH 10/13] run tests with PHPUnit 12.3 --- Tests/AbstractAsciiTestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/AbstractAsciiTestCase.php b/Tests/AbstractAsciiTestCase.php index aaf57e3..8ca8daf 100644 --- a/Tests/AbstractAsciiTestCase.php +++ b/Tests/AbstractAsciiTestCase.php @@ -69,7 +69,7 @@ public static function provideBytesAt(): array } #[DataProvider('provideIndexOf')] - public function testContainsAny(?int $result, string $string, $needle) + public function testContainsAny(?int $result, string $string, $needle, int $offset) { $instance = static::createFromString($string); @@ -77,7 +77,7 @@ public function testContainsAny(?int $result, string $string, $needle) } #[DataProvider('provideIndexOfIgnoreCase')] - public function testContainsAnyIgnoreCase(?int $result, string $string, $needle) + public function testContainsAnyIgnoreCase(?int $result, string $string, $needle, int $offset) { $instance = static::createFromString($string); From 68acca99bbfa040a25a9d5121a023b0211725d29 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Aug 2025 14:47:58 +0200 Subject: [PATCH 11/13] [String] Deprecate implementing `__sleep/wakeup()` on string implementations --- AbstractString.php | 29 +++++++++++++++++++++++++++++ CHANGELOG.md | 5 +++++ LazyString.php | 29 +++++++++++++++++++++++++++++ UnicodeString.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 1 + 5 files changed, 110 insertions(+) diff --git a/AbstractString.php b/AbstractString.php index fc60f8f..69f6ba5 100644 --- a/AbstractString.php +++ b/AbstractString.php @@ -706,8 +706,37 @@ public function wordwrap(int $width = 75, string $break = "\n", bool $cut = fals return $str; } + public function __serialize(): array + { + if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) { + return ['string' => $this->string]; + } + + trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this)); + + $data = []; + foreach ($this->__sleep() as $key) { + try { + if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) { + $data[$key] = $r->getValue($this); + } + } catch (\ReflectionException) { + $data[$key] = $this->$key; + } + } + + return $data; + } + + /** + * @internal since Symfony 7.4, will be removed in 8.0 + * + * @final since Symfony 7.4, will be removed in 8.0 + */ public function __sleep(): array { + trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this)); + return ['string']; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 141036c..d5569be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Deprecate implementing `__sleep/wakeup()` on string implementations + 7.3 --- diff --git a/LazyString.php b/LazyString.php index b86d733..d250c28 100644 --- a/LazyString.php +++ b/LazyString.php @@ -101,6 +101,35 @@ public function __toString(): string } } + public function __serialize(): array + { + if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) { + $this->__toString(); + + return ['value' => $this->value]; + } + + trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this)); + + $data = []; + foreach ($this->__sleep() as $key) { + try { + if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) { + $data[$key] = $r->getValue($this); + } + } catch (\ReflectionException) { + $data[$key] = $this->$key; + } + } + + return $data; + } + + /** + * @internal since Symfony 7.4, will be removed in 8.0 + * + * @final since Symfony 7.4, will be removed in 8.0 + */ public function __sleep(): array { $this->__toString(); diff --git a/UnicodeString.php b/UnicodeString.php index 811ae02..4da506a 100644 --- a/UnicodeString.php +++ b/UnicodeString.php @@ -366,8 +366,54 @@ public function startsWith(string|iterable|AbstractString $prefix): bool return $prefix === $grapheme; } + public function __unserialize(array $data): void + { + if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class) { + trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this)); + } + + try { + if (\in_array(array_keys($data), [['string'], ["\0*\0string"]], true)) { + $this->string = $data['string'] ?? $data["\0*\0string"]; + + if ($wakeup) { + $this->__wakeup(); + } + + return; + } + + trigger_deprecation('symfony/string', '7.4', 'Passing more than just key "string" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this)); + + \Closure::bind(function ($data) use ($wakeup) { + foreach ($data as $key => $value) { + $this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value; + } + + if ($wakeup) { + $this->__wakeup(); + } + }, $this, static::class)($data); + } finally { + if (!$wakeup) { + if (!\is_string($this->string)) { + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); + } + + normalizer_is_normalized($this->string) ?: $this->string = normalizer_normalize($this->string); + } + } + } + + /** + * @internal since Symfony 7.4, will be removed in 8.0 + * + * @final since Symfony 7.4, will be removed in 8.0 + */ public function __wakeup(): void { + trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this)); + if (!\is_string($this->string)) { throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); } diff --git a/composer.json b/composer.json index a7ae848..887ea86 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ ], "require": { "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.33", "symfony/polyfill-intl-normalizer": "~1.0", From eb940c91a06831b6b60f688a73c33e71bb6290e0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Aug 2025 15:15:05 +0200 Subject: [PATCH 12/13] [Validator] Deprecate implementing `__sleep/wakeup()` on GenericMetadata implementations --- AbstractString.php | 4 +--- LazyString.php | 6 +++--- UnicodeString.php | 4 +--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/AbstractString.php b/AbstractString.php index 69f6ba5..4777f95 100644 --- a/AbstractString.php +++ b/AbstractString.php @@ -729,9 +729,7 @@ public function __serialize(): array } /** - * @internal since Symfony 7.4, will be removed in 8.0 - * - * @final since Symfony 7.4, will be removed in 8.0 + * @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0 */ public function __sleep(): array { diff --git a/LazyString.php b/LazyString.php index d250c28..eafc9ca 100644 --- a/LazyString.php +++ b/LazyString.php @@ -126,12 +126,12 @@ public function __serialize(): array } /** - * @internal since Symfony 7.4, will be removed in 8.0 - * - * @final since Symfony 7.4, will be removed in 8.0 + * @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0 */ public function __sleep(): array { + trigger_deprecation('symfony/string', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this)); + $this->__toString(); return ['value']; diff --git a/UnicodeString.php b/UnicodeString.php index 4da506a..f2bf1d0 100644 --- a/UnicodeString.php +++ b/UnicodeString.php @@ -406,9 +406,7 @@ public function __unserialize(array $data): void } /** - * @internal since Symfony 7.4, will be removed in 8.0 - * - * @final since Symfony 7.4, will be removed in 8.0 + * @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0 */ public function __wakeup(): void { From 3ba35cbf2a48e775a1f3b44d357b37fe2215a2ea Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Aug 2025 16:45:04 +0200 Subject: [PATCH 13/13] [Mime] Deprecate implementing `__sleep/wakeup()` on `AbstractPart` implementations --- AbstractString.php | 2 +- LazyString.php | 2 +- UnicodeString.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AbstractString.php b/AbstractString.php index 4777f95..402839c 100644 --- a/AbstractString.php +++ b/AbstractString.php @@ -708,7 +708,7 @@ public function wordwrap(int $width = 75, string $break = "\n", bool $cut = fals public function __serialize(): array { - if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) { + if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) { return ['string' => $this->string]; } diff --git a/LazyString.php b/LazyString.php index eafc9ca..c7a354c 100644 --- a/LazyString.php +++ b/LazyString.php @@ -103,7 +103,7 @@ public function __toString(): string public function __serialize(): array { - if (self::class === (new \ReflectionMethod($this, '__sleep'))->class) { + if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) { $this->__toString(); return ['value' => $this->value]; diff --git a/UnicodeString.php b/UnicodeString.php index f2bf1d0..48d524f 100644 --- a/UnicodeString.php +++ b/UnicodeString.php @@ -368,7 +368,7 @@ public function startsWith(string|iterable|AbstractString $prefix): bool public function __unserialize(array $data): void { - if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class) { + if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) { trigger_deprecation('symfony/string', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this)); }