Skip to content

Commit 40e975e

Browse files
Merge branch '5.1' into 5.x
* 5.1: fix merge fix merge Remove branch-version (keep them for contracts only) [HttpClient] relax auth bearer format requirements [PHPUnitBridge] Silence errors from mkdir() [DependencyInjection] Preload classes with union types correctly. [Serializer] fix decoding float XML attributes starting with 0 add missing dutch translations [TwigBridge] Remove "transchoice" from the code base Support PHPUnit 8 and PHPUnit 9 in constraint compatibility trait Add expectDeprecation, expectNotice, expectWarning, and expectError to TestCase polyfill [String] fix before/after[Last]() returning the empty string instead of the original one on non-match Add missing exporter function for PHPUnit 7 [Validator] Add missing romanian translations [String] fix slicing in UnicodeString [Cache] Use correct expiry in ChainAdapter do not translate null placeholders or titles
2 parents c2979f2 + a97573e commit 40e975e

6 files changed

+75
-47
lines changed

AbstractString.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public static function wrap(array $values): array
9898
public function after($needle, bool $includeNeedle = false, int $offset = 0): self
9999
{
100100
$str = clone $this;
101-
$str->string = '';
102101
$i = \PHP_INT_MAX;
103102

104103
foreach ((array) $needle as $n) {
@@ -130,7 +129,6 @@ public function after($needle, bool $includeNeedle = false, int $offset = 0): se
130129
public function afterLast($needle, bool $includeNeedle = false, int $offset = 0): self
131130
{
132131
$str = clone $this;
133-
$str->string = '';
134132
$i = null;
135133

136134
foreach ((array) $needle as $n) {
@@ -167,7 +165,6 @@ abstract public function append(string ...$suffix): self;
167165
public function before($needle, bool $includeNeedle = false, int $offset = 0): self
168166
{
169167
$str = clone $this;
170-
$str->string = '';
171168
$i = \PHP_INT_MAX;
172169

173170
foreach ((array) $needle as $n) {
@@ -199,7 +196,6 @@ public function before($needle, bool $includeNeedle = false, int $offset = 0): s
199196
public function beforeLast($needle, bool $includeNeedle = false, int $offset = 0): self
200197
{
201198
$str = clone $this;
202-
$str->string = '';
203199
$i = null;
204200

205201
foreach ((array) $needle as $n) {

Tests/AbstractAsciiTestCase.php

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,37 @@ public static function provideSlice()
597597
['awesome', 'Symfony is awesome', 11, 7],
598598
['awesome', 'Symfony is awesome', -7, null],
599599
['awe', 'Symfony is awesome', -7, -4],
600+
['S', 'Symfony is awesome', -42, 1],
601+
['', 'Symfony is awesome', 42, 1],
602+
['', 'Symfony is awesome', 0, -42],
603+
];
604+
}
605+
606+
/**
607+
* @dataProvider provideSplice
608+
*/
609+
public function testSplice(string $expected, int $start, int $length = null)
610+
{
611+
$this->assertEquals(
612+
static::createFromString($expected),
613+
static::createFromString('Symfony is awesome')->splice('X', $start, $length)
614+
);
615+
}
616+
617+
public static function provideSplice()
618+
{
619+
return [
620+
['X is awesome', 0, 7],
621+
['SymfonyXis awesome', 7, 1],
622+
['Symfony X awesome', 8, 2],
623+
['Symfony X', 8, null],
624+
['Symfony isXawesome', 10, 1],
625+
['Symfony is X', 11, 7],
626+
['Symfony is X', -7, null],
627+
['Symfony is Xsome', -7, -4],
628+
['Xymfony is awesome', -42, 1],
629+
['Symfony is awesomeX', 42, 1],
630+
['XSymfony is awesome', 0, -42],
600631
];
601632
}
602633

@@ -766,12 +797,12 @@ public function testBeforeAfter(string $expected, string $needle, string $origin
766797
public static function provideBeforeAfter()
767798
{
768799
return [
769-
['', '', 'hello world', 0, true],
770-
['', '', 'hello world', 0, false],
771-
['', 'w', 'hello World', 0, true],
772-
['', 'w', 'hello World', 0, false],
773-
['', 'o', 'hello world', 10, true],
774-
['', 'o', 'hello world', 10, false],
800+
['hello world', '', 'hello world', 0, true],
801+
['hello world', '', 'hello world', 0, false],
802+
['hello World', 'w', 'hello World', 0, true],
803+
['hello World', 'w', 'hello World', 0, false],
804+
['hello world', 'o', 'hello world', 10, true],
805+
['hello world', 'o', 'hello world', 10, false],
775806
['hello ', 'w', 'hello world', 0, true],
776807
['world', 'w', 'hello world', 0, false],
777808
['hello W', 'O', 'hello WORLD', 0, true],
@@ -794,12 +825,12 @@ public function testBeforeAfterIgnoreCase(string $expected, string $needle, stri
794825
public static function provideBeforeAfterIgnoreCase()
795826
{
796827
return [
797-
['', '', 'hello world', 0, true],
798-
['', '', 'hello world', 0, false],
799-
['', 'foo', 'hello world', 0, true],
800-
['', 'foo', 'hello world', 0, false],
801-
['', 'o', 'hello world', 10, true],
802-
['', 'o', 'hello world', 10, false],
828+
['hello world', '', 'hello world', 0, true],
829+
['hello world', '', 'hello world', 0, false],
830+
['hello world', 'foo', 'hello world', 0, true],
831+
['hello world', 'foo', 'hello world', 0, false],
832+
['hello world', 'o', 'hello world', 10, true],
833+
['hello world', 'o', 'hello world', 10, false],
803834
['hello ', 'w', 'hello world', 0, true],
804835
['world', 'w', 'hello world', 0, false],
805836
['hello ', 'W', 'hello world', 0, true],
@@ -822,12 +853,12 @@ public function testBeforeAfterLast(string $expected, string $needle, string $or
822853
public static function provideBeforeAfterLast()
823854
{
824855
return [
825-
['', '', 'hello world', 0, true],
826-
['', '', 'hello world', 0, false],
827-
['', 'L', 'hello world', 0, true],
828-
['', 'L', 'hello world', 0, false],
829-
['', 'o', 'hello world', 10, true],
830-
['', 'o', 'hello world', 10, false],
856+
['hello world', '', 'hello world', 0, true],
857+
['hello world', '', 'hello world', 0, false],
858+
['hello world', 'L', 'hello world', 0, true],
859+
['hello world', 'L', 'hello world', 0, false],
860+
['hello world', 'o', 'hello world', 10, true],
861+
['hello world', 'o', 'hello world', 10, false],
831862
['hello wor', 'l', 'hello world', 0, true],
832863
['ld', 'l', 'hello world', 0, false],
833864
['hello w', 'o', 'hello world', 0, true],
@@ -851,12 +882,12 @@ public function testBeforeAfterLastIgnoreCase(string $expected, string $needle,
851882
public static function provideBeforeAfterLastIgnoreCase()
852883
{
853884
return [
854-
['', '', 'hello world', 0, true],
855-
['', '', 'hello world', 0, false],
856-
['', 'FOO', 'hello world', 0, true],
857-
['', 'FOO', 'hello world', 0, false],
858-
['', 'o', 'hello world', 10, true],
859-
['', 'o', 'hello world', 10, false],
885+
['hello world', '', 'hello world', 0, true],
886+
['hello world', '', 'hello world', 0, false],
887+
['hello world', 'FOO', 'hello world', 0, true],
888+
['hello world', 'FOO', 'hello world', 0, false],
889+
['hello world', 'o', 'hello world', 10, true],
890+
['hello world', 'o', 'hello world', 10, false],
860891
['hello wor', 'l', 'hello world', 0, true],
861892
['ld', 'l', 'hello world', 0, false],
862893
['hello wor', 'L', 'hello world', 0, true],

Tests/AbstractUnicodeTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ public static function provideBeforeAfterIgnoreCase(): array
406406
['', '', 'déjàdéjà', 0, true],
407407
['éjàdéjà', 'é', 'déjàdéjà', 0, false],
408408
['d', 'é', 'déjàdéjà', 0, true],
409-
['', 'Ç', 'déjàdéjà', 0, false],
410-
['', 'Ç', 'déjàdéjà', 0, true],
409+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
410+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, true],
411411
]
412412
);
413413
}
@@ -417,8 +417,8 @@ public static function provideBeforeAfterLast(): array
417417
return array_merge(
418418
parent::provideBeforeAfterLast(),
419419
[
420-
['', 'Ç', 'déjàdéjà', 0, false],
421-
['', 'Ç', 'déjàdéjà', 0, true],
420+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
421+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, true],
422422
['éjà', 'é', 'déjàdéjà', 0, false],
423423
['déjàd', 'é', 'déjàdéjà', 0, true],
424424
]
@@ -430,7 +430,7 @@ public static function provideBeforeAfterLastIgnoreCase(): array
430430
return array_merge(
431431
parent::provideBeforeAfterLastIgnoreCase(),
432432
[
433-
['', 'Ç', 'déjàdéjà', 0, false],
433+
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
434434
['éjà', 'é', 'déjàdéjà', 0, false],
435435
['éjà', 'É', 'déjàdéjà', 0, false],
436436
]

Tests/UnicodeStringTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public static function provideBeforeAfterIgnoreCase(): array
186186
return array_merge(
187187
parent::provideBeforeAfterIgnoreCase(),
188188
[
189-
['', 'छेछे', 'दछेच्नुअ', 0, false],
190-
['', 'छेछे', 'दछेच्नुअ', 0, true],
189+
['दछेच्नुअ', 'छेछे', 'दछेच्नुअ', 0, false],
190+
['दछेच्नुअ', 'छेछे', 'दछेच्नुअ', 0, true],
191191
['छेच्नुअ', 'छे', 'दछेच्नुअ', 0, false],
192192
['', 'छे', 'दछेच्नुअ', 0, true],
193193
]
@@ -199,8 +199,8 @@ public static function provideBeforeAfterLast(): array
199199
return array_merge(
200200
parent::provideBeforeAfterLast(),
201201
[
202-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
203-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
202+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
203+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
204204
['-दछेच्नु', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, false],
205205
['दछेच्नुअ-दछेच्नु-अद', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, true],
206206
]
@@ -212,8 +212,8 @@ public static function provideBeforeAfterLastIgnoreCase(): array
212212
return array_merge(
213213
parent::provideBeforeAfterLastIgnoreCase(),
214214
[
215-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
216-
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
215+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
216+
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
217217
['-दछेच्नु', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, false],
218218
['दछेच्नुअ-दछेच्नु-अद', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, true],
219219
]

UnicodeString.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,22 @@ public function replaceMatches(string $fromRegexp, $to): AbstractString
267267
public function slice(int $start = 0, int $length = null): AbstractString
268268
{
269269
$str = clone $this;
270-
try {
271-
$str->string = (string) grapheme_substr($this->string, $start, $length ?? 2147483647);
272-
} catch (\ValueError $e) {
273-
$str->string = '';
270+
271+
if (\PHP_VERSION_ID < 80000 && 0 > $start && grapheme_strlen($this->string) < -$start) {
272+
$start = 0;
274273
}
274+
$str->string = (string) grapheme_substr($this->string, $start, $length ?? 2147483647);
275275

276276
return $str;
277277
}
278278

279279
public function splice(string $replacement, int $start = 0, int $length = null): AbstractString
280280
{
281281
$str = clone $this;
282+
283+
if (\PHP_VERSION_ID < 80000 && 0 > $start && grapheme_strlen($this->string) < -$start) {
284+
$start = 0;
285+
}
282286
$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
283287
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
284288
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,5 @@
3636
"/Tests/"
3737
]
3838
},
39-
"minimum-stability": "dev",
40-
"extra": {
41-
"branch-version": "5.2"
42-
}
39+
"minimum-stability": "dev"
4340
}

0 commit comments

Comments
 (0)