diff --git a/src/Tempest/Support/src/StringHelper.php b/src/Tempest/Support/src/StringHelper.php index 0ae045f34..b94ad3c07 100644 --- a/src/Tempest/Support/src/StringHelper.php +++ b/src/Tempest/Support/src/StringHelper.php @@ -763,10 +763,10 @@ public function stripTags(null|string|array $allowed = null): self * * ### Example * ```php - * str('Lorem ipsum sit amet')->insert(11, ' dolor'); // Lorem ipsum dolor sit amet + * str('Lorem ipsum sit amet')->insertAt(11, ' dolor'); // Lorem ipsum dolor sit amet * ``` */ - public function insert(int $position, string $string): self + public function insertAt(int $position, string $string): self { return new self( mb_substr($this->string, 0, $position) . $string . mb_substr($this->string, $position) diff --git a/src/Tempest/Support/tests/StringHelperTest.php b/src/Tempest/Support/tests/StringHelperTest.php index 56643a9b8..05405b5b9 100644 --- a/src/Tempest/Support/tests/StringHelperTest.php +++ b/src/Tempest/Support/tests/StringHelperTest.php @@ -522,16 +522,16 @@ public function test_split(): void $this->assertSame(['foo', 'bar', 'baz', '22'], str('foobarbaz22')->split(3)->toArray()); } - public function test_insert(): void - { - $this->assertSame('foo', str()->insert(0, 'foo')->toString()); - $this->assertSame('foo', str()->insert(-1, 'foo')->toString()); - $this->assertSame('foo', str()->insert(100, 'foo')->toString()); - $this->assertSame('foo', str()->insert(-100, 'foo')->toString()); - $this->assertSame('foobar', str('bar')->insert(0, 'foo')->toString()); - $this->assertSame('barfoo', str('bar')->insert(3, 'foo')->toString()); - $this->assertSame('foobarbaz', str('foobaz')->insert(3, 'bar')->toString()); - $this->assertSame('123', str('13')->insert(-1, '2')->toString()); + public function test_insert_at(): void + { + $this->assertSame('foo', str()->insertAt(0, 'foo')->toString()); + $this->assertSame('foo', str()->insertAt(-1, 'foo')->toString()); + $this->assertSame('foo', str()->insertAt(100, 'foo')->toString()); + $this->assertSame('foo', str()->insertAt(-100, 'foo')->toString()); + $this->assertSame('foobar', str('bar')->insertAt(0, 'foo')->toString()); + $this->assertSame('barfoo', str('bar')->insertAt(3, 'foo')->toString()); + $this->assertSame('foobarbaz', str('foobaz')->insertAt(3, 'bar')->toString()); + $this->assertSame('123', str('13')->insertAt(-1, '2')->toString()); } public function test_replace_at(): void