Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit015b81a

Browse files
committed
[String] wrap(): test and fix
1 parenta306d99 commit015b81a

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

‎src/Symfony/Component/String/AbstractString.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ public static function wrap(array $values): array
7575
$keys =null;
7676

7777
foreach ($valuesas$k =>$v) {
78-
++$i;
79-
8078
if (\is_string($k) &&'' !==$k &&$k !==$j = (string)newstatic($k)) {
8179
$keys =$keys ??array_keys($values);
82-
array_splice($keys,$i,1, [$j]);
80+
$keys[$i] =$j;
8381
}
8482

8583
if (\is_string($v)) {
8684
$values[$k] =newstatic($v);
8785
}elseif (\is_array($v) &&$values[$k] !==$v =static::wrap($v)) {
8886
$values[$k] =$v;
8987
}
88+
89+
++$i;
9090
}
9191

9292
returnnull !==$keys ?array_combine($keys,$values) :$values;

‎src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ public function testCreateFromEmptyString()
3434
$this->assertTrue($instance->isEmpty());
3535
}
3636

37+
/**
38+
* @dataProvider provideWrap
39+
*/
40+
publicfunctiontestWrap(array$expected,array$values)
41+
{
42+
$s =static::createFromString('');
43+
44+
$this->assertEquals($expected,$s::wrap($values));
45+
}
46+
47+
publicstaticfunctionprovideWrap():array
48+
{
49+
return [
50+
[[], []],
51+
[
52+
['abc' =>static::createFromString('foo'),1,static::createFromString('bar'),'baz' =>true],
53+
['abc' =>'foo',1,'bar','baz' =>true],
54+
],
55+
[
56+
['a' => ['b' =>static::createFromString('c'), [static::createFromString('d')]],static::createFromString('e')],
57+
['a' => ['b' =>'c', ['d']],'e'],
58+
],
59+
];
60+
}
61+
3762
/**
3863
* @dataProvider provideLength
3964
*/

‎src/Symfony/Component/String/Tests/UnicodeStringTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ protected static function createFromString(string $string): AbstractString
2121
returnnewUnicodeString($string);
2222
}
2323

24+
publicstaticfunctionprovideWrap():array
25+
{
26+
returnarray_merge(
27+
parent::provideWrap(),
28+
[
29+
[
30+
['Käse' =>static::createFromString('köstlich'),'fromage' =>static::createFromString('délicieux')],
31+
["Ka\u{0308}se" =>"ko\u{0308}stlich",'fromage' =>'délicieux'],
32+
],
33+
[
34+
['a' =>1,'ä' => ['ö' =>2,'ü' =>3]],
35+
['a' =>1,"a\u{0308}" => ["o\u{0308}" =>2,'ü' =>3]],
36+
],
37+
]
38+
);
39+
}
40+
2441
publicstaticfunctionprovideLength():array
2542
{
2643
returnarray_merge(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp