Skip to content

Commit

Permalink
Merge branch '5.1' into 5.x
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Oct 24, 2020
2 parents c2979f2 + a97573e commit 40e975e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 47 deletions.
4 changes: 0 additions & 4 deletions AbstractString.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public static function wrap(array $values): array
public function after($needle, bool $includeNeedle = false, int $offset = 0): self
{
$str = clone $this;
$str->string = '';
$i = \PHP_INT_MAX;

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

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

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

foreach ((array) $needle as $n) {
Expand Down
79 changes: 55 additions & 24 deletions Tests/AbstractAsciiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,37 @@ public static function provideSlice()
['awesome', 'Symfony is awesome', 11, 7],
['awesome', 'Symfony is awesome', -7, null],
['awe', 'Symfony is awesome', -7, -4],
['S', 'Symfony is awesome', -42, 1],
['', 'Symfony is awesome', 42, 1],
['', 'Symfony is awesome', 0, -42],
];
}

/**
* @dataProvider provideSplice
*/
public function testSplice(string $expected, int $start, int $length = null)
{
$this->assertEquals(
static::createFromString($expected),
static::createFromString('Symfony is awesome')->splice('X', $start, $length)
);
}

public static function provideSplice()
{
return [
['X is awesome', 0, 7],
['SymfonyXis awesome', 7, 1],
['Symfony X awesome', 8, 2],
['Symfony X', 8, null],
['Symfony isXawesome', 10, 1],
['Symfony is X', 11, 7],
['Symfony is X', -7, null],
['Symfony is Xsome', -7, -4],
['Xymfony is awesome', -42, 1],
['Symfony is awesomeX', 42, 1],
['XSymfony is awesome', 0, -42],
];
}

Expand Down Expand Up @@ -766,12 +797,12 @@ public function testBeforeAfter(string $expected, string $needle, string $origin
public static function provideBeforeAfter()
{
return [
['', '', 'hello world', 0, true],
['', '', 'hello world', 0, false],
['', 'w', 'hello World', 0, true],
['', 'w', 'hello World', 0, false],
['', 'o', 'hello world', 10, true],
['', 'o', 'hello world', 10, false],
['hello world', '', 'hello world', 0, true],
['hello world', '', 'hello world', 0, false],
['hello World', 'w', 'hello World', 0, true],
['hello World', 'w', 'hello World', 0, false],
['hello world', 'o', 'hello world', 10, true],
['hello world', 'o', 'hello world', 10, false],
['hello ', 'w', 'hello world', 0, true],
['world', 'w', 'hello world', 0, false],
['hello W', 'O', 'hello WORLD', 0, true],
Expand All @@ -794,12 +825,12 @@ public function testBeforeAfterIgnoreCase(string $expected, string $needle, stri
public static function provideBeforeAfterIgnoreCase()
{
return [
['', '', 'hello world', 0, true],
['', '', 'hello world', 0, false],
['', 'foo', 'hello world', 0, true],
['', 'foo', 'hello world', 0, false],
['', 'o', 'hello world', 10, true],
['', 'o', 'hello world', 10, false],
['hello world', '', 'hello world', 0, true],
['hello world', '', 'hello world', 0, false],
['hello world', 'foo', 'hello world', 0, true],
['hello world', 'foo', 'hello world', 0, false],
['hello world', 'o', 'hello world', 10, true],
['hello world', 'o', 'hello world', 10, false],
['hello ', 'w', 'hello world', 0, true],
['world', 'w', 'hello world', 0, false],
['hello ', 'W', 'hello world', 0, true],
Expand All @@ -822,12 +853,12 @@ public function testBeforeAfterLast(string $expected, string $needle, string $or
public static function provideBeforeAfterLast()
{
return [
['', '', 'hello world', 0, true],
['', '', 'hello world', 0, false],
['', 'L', 'hello world', 0, true],
['', 'L', 'hello world', 0, false],
['', 'o', 'hello world', 10, true],
['', 'o', 'hello world', 10, false],
['hello world', '', 'hello world', 0, true],
['hello world', '', 'hello world', 0, false],
['hello world', 'L', 'hello world', 0, true],
['hello world', 'L', 'hello world', 0, false],
['hello world', 'o', 'hello world', 10, true],
['hello world', 'o', 'hello world', 10, false],
['hello wor', 'l', 'hello world', 0, true],
['ld', 'l', 'hello world', 0, false],
['hello w', 'o', 'hello world', 0, true],
Expand All @@ -851,12 +882,12 @@ public function testBeforeAfterLastIgnoreCase(string $expected, string $needle,
public static function provideBeforeAfterLastIgnoreCase()
{
return [
['', '', 'hello world', 0, true],
['', '', 'hello world', 0, false],
['', 'FOO', 'hello world', 0, true],
['', 'FOO', 'hello world', 0, false],
['', 'o', 'hello world', 10, true],
['', 'o', 'hello world', 10, false],
['hello world', '', 'hello world', 0, true],
['hello world', '', 'hello world', 0, false],
['hello world', 'FOO', 'hello world', 0, true],
['hello world', 'FOO', 'hello world', 0, false],
['hello world', 'o', 'hello world', 10, true],
['hello world', 'o', 'hello world', 10, false],
['hello wor', 'l', 'hello world', 0, true],
['ld', 'l', 'hello world', 0, false],
['hello wor', 'L', 'hello world', 0, true],
Expand Down
10 changes: 5 additions & 5 deletions Tests/AbstractUnicodeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ public static function provideBeforeAfterIgnoreCase(): array
['', '', 'déjàdéjà', 0, true],
['éjàdéjà', 'é', 'déjàdéjà', 0, false],
['d', 'é', 'déjàdéjà', 0, true],
['', 'Ç', 'déjàdéjà', 0, false],
['', 'Ç', 'déjàdéjà', 0, true],
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
['déjàdéjà', 'Ç', 'déjàdéjà', 0, true],
]
);
}
Expand All @@ -417,8 +417,8 @@ public static function provideBeforeAfterLast(): array
return array_merge(
parent::provideBeforeAfterLast(),
[
['', 'Ç', 'déjàdéjà', 0, false],
['', 'Ç', 'déjàdéjà', 0, true],
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
['déjàdéjà', 'Ç', 'déjàdéjà', 0, true],
['éjà', 'é', 'déjàdéjà', 0, false],
['déjàd', 'é', 'déjàdéjà', 0, true],
]
Expand All @@ -430,7 +430,7 @@ public static function provideBeforeAfterLastIgnoreCase(): array
return array_merge(
parent::provideBeforeAfterLastIgnoreCase(),
[
['', 'Ç', 'déjàdéjà', 0, false],
['déjàdéjà', 'Ç', 'déjàdéjà', 0, false],
['éjà', 'é', 'déjàdéjà', 0, false],
['éjà', 'É', 'déjàdéjà', 0, false],
]
Expand Down
12 changes: 6 additions & 6 deletions Tests/UnicodeStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public static function provideBeforeAfterIgnoreCase(): array
return array_merge(
parent::provideBeforeAfterIgnoreCase(),
[
['', 'छेछे', 'दछेच्नुअ', 0, false],
['', 'छेछे', 'दछेच्नुअ', 0, true],
['दछेच्नुअ', 'छेछे', 'दछेच्नुअ', 0, false],
['दछेच्नुअ', 'छेछे', 'दछेच्नुअ', 0, true],
['छेच्नुअ', 'छे', 'दछेच्नुअ', 0, false],
['', 'छे', 'दछेच्नुअ', 0, true],
]
Expand All @@ -199,8 +199,8 @@ public static function provideBeforeAfterLast(): array
return array_merge(
parent::provideBeforeAfterLast(),
[
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
['-दछेच्नु', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, false],
['दछेच्नुअ-दछेच्नु-अद', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, true],
]
Expand All @@ -212,8 +212,8 @@ public static function provideBeforeAfterLastIgnoreCase(): array
return array_merge(
parent::provideBeforeAfterLastIgnoreCase(),
[
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
['', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, false],
['दछेच्नुअ-दछेच्नु-अदछेच्नु', 'छेछे', 'दछेच्नुअ-दछेच्नु-अदछेच्नु', 0, true],
['-दछेच्नु', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, false],
['दछेच्नुअ-दछेच्नु-अद', '-द', 'दछेच्नुअ-दछेच्नु-अद-दछेच्नु', 0, true],
]
Expand Down
12 changes: 8 additions & 4 deletions UnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,22 @@ public function replaceMatches(string $fromRegexp, $to): AbstractString
public function slice(int $start = 0, int $length = null): AbstractString
{
$str = clone $this;
try {
$str->string = (string) grapheme_substr($this->string, $start, $length ?? 2147483647);
} catch (\ValueError $e) {
$str->string = '';

if (\PHP_VERSION_ID < 80000 && 0 > $start && grapheme_strlen($this->string) < -$start) {
$start = 0;
}
$str->string = (string) grapheme_substr($this->string, $start, $length ?? 2147483647);

return $str;
}

public function splice(string $replacement, int $start = 0, int $length = null): AbstractString
{
$str = clone $this;

if (\PHP_VERSION_ID < 80000 && 0 > $start && grapheme_strlen($this->string) < -$start) {
$start = 0;
}
$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@
"/Tests/"
]
},
"minimum-stability": "dev",
"extra": {
"branch-version": "5.2"
}
"minimum-stability": "dev"
}

0 comments on commit 40e975e

Please sign in to comment.