Skip to content

Commit

Permalink
refactor: rename insert to insertAt
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Nov 13, 2024
1 parent 31b54a3 commit 04b027c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Tempest/Support/src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions src/Tempest/Support/tests/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04b027c

Please # to comment.