Skip to content

Commit

Permalink
fix chopStart and chopEnd tests (#53812)
Browse files Browse the repository at this point in the history
the arrays were using duplicate keys, which meant only the latest defined element was running an assertion.

converted them to indexed arrays, and then adjusted the destructuring to treat the first element as the `$subject`.
  • Loading branch information
browner12 authored Dec 10, 2024
1 parent 5bd1ec6 commit f278399
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1590,18 +1590,18 @@ public function testFromBase64()
public function testChopStart()
{
foreach ([
'http://laravel.com' => ['http://', 'laravel.com'],
'http://-http://' => ['http://', '-http://'],
'http://laravel.com' => ['htp:/', 'http://laravel.com'],
'http://laravel.com' => ['http://www.', 'http://laravel.com'],
'http://laravel.com' => ['-http://', 'http://laravel.com'],
'http://laravel.com' => [['https://', 'http://'], 'laravel.com'],
'http://www.laravel.com' => [['http://', 'www.'], 'www.laravel.com'],
'http://http-is-fun.test' => ['http://', 'http-is-fun.test'],
'πŸŒŠβœ‹' => ['🌊', 'βœ‹'],
'πŸŒŠβœ‹' => ['βœ‹', 'πŸŒŠβœ‹'],
] as $subject => $value) {
[$needle, $expected] = $value;
['http://laravel.com', 'http://', 'laravel.com'],
['http://-http://', 'http://', '-http://'],
['http://laravel.com', 'htp:/', 'http://laravel.com'],
['http://laravel.com', 'http://www.', 'http://laravel.com'],
['http://laravel.com', '-http://', 'http://laravel.com'],
['http://laravel.com', ['https://', 'http://'], 'laravel.com'],
['http://www.laravel.com', ['http://', 'www.'], 'www.laravel.com'],
['http://http-is-fun.test', 'http://', 'http-is-fun.test'],
['πŸŒŠβœ‹', '🌊', 'βœ‹'],
['πŸŒŠβœ‹', 'βœ‹', 'πŸŒŠβœ‹'],
] as $value) {
[$subject, $needle, $expected] = $value;

$this->assertSame($expected, Str::chopStart($subject, $needle));
}
Expand All @@ -1610,18 +1610,18 @@ public function testChopStart()
public function testChopEnd()
{
foreach ([
'path/to/file.php' => ['.php', 'path/to/file'],
'.php-.php' => ['.php', '.php-'],
'path/to/file.php' => ['.ph', 'path/to/file.php'],
'path/to/file.php' => ['foo.php', 'path/to/file.php'],
'path/to/file.php' => ['.php-', 'path/to/file.php'],
'path/to/file.php' => [['.html', '.php'], 'path/to/file'],
'path/to/file.php' => [['.php', 'file'], 'path/to/file'],
'path/to/php.php' => ['.php', 'path/to/php'],
'βœ‹πŸŒŠ' => ['🌊', 'βœ‹'],
'βœ‹πŸŒŠ' => ['βœ‹', 'βœ‹πŸŒŠ'],
] as $subject => $value) {
[$needle, $expected] = $value;
['path/to/file.php', '.php', 'path/to/file'],
['.php-.php', '.php', '.php-'],
['path/to/file.php', '.ph', 'path/to/file.php'],
['path/to/file.php', 'foo.php', 'path/to/file.php'],
['path/to/file.php', '.php-', 'path/to/file.php'],
['path/to/file.php', ['.html', '.php'], 'path/to/file'],
['path/to/file.php', ['.php', 'file'], 'path/to/file'],
['path/to/php.php', '.php', 'path/to/php'],
['βœ‹πŸŒŠ', '🌊', 'βœ‹'],
['βœ‹πŸŒŠ', 'βœ‹', 'βœ‹πŸŒŠ'],
] as $value) {
[$subject, $needle, $expected] = $value;

$this->assertSame($expected, Str::chopEnd($subject, $needle));
}
Expand Down

0 comments on commit f278399

Please sign in to comment.