8000 feature #58545 [String] Add `AbstractString::pascal()` method (raffae… · symfony/symfony@e23a0d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit e23a0d2

Browse files
committed
feature #58545 [String] Add AbstractString::pascal() method (raffaelecarelle)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [String] Add `AbstractString::pascal()` method | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT Introduce a new `pascal()` method to the `AbstractString` class to transform strings to PascalCase. Accompany the implementation with relevant test cases to ensure correctness and immutability. Update the changelog to document this new method. Commits ------- 3cb12a0 [String] Add `AbstractString::pascal()` method
2 parents fc65c8f + 3cb12a0 commit e23a0d2

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

src/Symfony/Component/String/AbstractString.php

+5
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ public function kebab(): static
438438
return $this->snake()->replace('_', '-');
439439
}
440440

441+
public function pascal(): static
442+
{
443+
return $this->camel()->title();
444+
}
445+
441446
abstract public function splice(string $replacement, int $start = 0, ?int $length = null): static;
442447

443448
/**

src/Symfony/Component/String/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add the `AbstractString::pascal()` method
8+
49
7.2
510
---
611

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

+27
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,33 @@ public static function provideKebab(): array
11181118
];
11191119
}
11201120

1121+
/**
1122+
* @dataProvider providePascal
1123+
*/
1124+
public function testPascal(string $expectedString, string $origin)
1125+
{
1126+
$instance = static::createFromString($origin)->pascal();
1127+
1128+
$this->assertEquals(static::createFromString($expectedString), $instance);
1129+
$this->assertNotSame($origin, $instance, 'Strings should be immutable');
1130+
}
1131+
1132+
public static function providePascal(): array
1133+
{
1134+
return [
1135+
['', ''],
1136+
['XY', 'x_y'],
1137+
['XuYo', 'xu_yo'],
1138+
['SymfonyIsGreat', 'symfony_is_great'],
1139+
['Symfony5IsGreat', 'symfony_5_is_great'],
1140+
['SymfonyIsGreat', 'Symfony is great'],
1141+
['SYMFONYISGREAT', 'SYMFONY_IS_GREAT'],
1142+
['SymfonyIsAGreatFramework', 'Symfony is a great framework'],
1143+
['SymfonyIsGREAT', '*Symfony* is GREAT!!'],
1144+
['SYMFONY', 'SYMFONY'],
1145+
];
1146+
}
1147+
11211148
/**
11221149
* @dataProvider provideStartsWith
11231150
*/

src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php

+11
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,17 @@ public static function provideCamel()
655655
);
656656
}
657657

658+
public static function providePascal(): array
659+
{
660+
return array_merge(
661+
parent::providePascal(),
662+
[
663+
['SymfonyIstÄußerstCool', 'symfonyIstÄußerstCool'],
664+
['SymfonyWithEmojis', 'Symfony with 😃 emojis'],
665+
]
666+
);
667+
}
668+
658669
public static function provideSnake()
659670
{
660671
return array_merge(

0 commit comments

Comments
 (0)
0