Skip to content

Commit

Permalink
[9.x] Stringable exactly not match with other Stringable variable (#4…
Browse files Browse the repository at this point in the history
…1846)

* issue-41845 cast string arg on exatcly method on Stringable class when compare two string

* issue-41845 update Stringable class to exactly method match with another Stringable variable

* issue-41845 fix indentation on SupportStringableTest

* issue-41845 fix indentation on Stringable class

* Update Stringable.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
medeiroz and taylorotwell authored Apr 6, 2022
1 parent f981e23 commit 6ed23a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Support/Stringable.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ public function endsWith($needles)
/**
* Determine if the string is an exact match with the given value.
*
* @param string $value
* @param \Illuminate\Support\Stringable|string $value
* @return bool
*/
public function exactly($value)
{
if ($value instanceof Stringable) {
$value = $value->toString();
}

return $this->value === $value;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,15 @@ public function testGet()
$this->assertSame('foo', $this->stringable('foo')->value());
$this->assertSame('foo', $this->stringable('foo')->toString());
}

public function testExactly()
{
$this->assertTrue($this->stringable('foo')->exactly($this->stringable('foo')));
$this->assertTrue($this->stringable('foo')->exactly('foo'));

$this->assertFalse($this->stringable('Foo')->exactly($this->stringable('foo')));
$this->assertFalse($this->stringable('Foo')->exactly('foo'));
$this->assertFalse($this->stringable('[]')->exactly([]));
$this->assertFalse($this->stringable('0')->exactly(0));
}
}

0 comments on commit 6ed23a5

Please sign in to comment.