From f278399f483dd1e5fbde83bbb04d0063bd4ecac7 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 10 Dec 2024 08:54:43 -0600 Subject: [PATCH] fix `chopStart` and `chopEnd` tests (#53812) 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`. --- tests/Support/SupportStrTest.php | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 54eef56eec26..ae6e0febefbd 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -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)); } @@ -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)); }