Skip to content

Commit 6ed23a5

Browse files
[9.x] Stringable exactly not match with other Stringable variable (#41846)
* 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]>
1 parent f981e23 commit 6ed23a5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Illuminate/Support/Stringable.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,15 @@ public function endsWith($needles)
210210
/**
211211
* Determine if the string is an exact match with the given value.
212212
*
213-
* @param string $value
213+
* @param \Illuminate\Support\Stringable|string $value
214214
* @return bool
215215
*/
216216
public function exactly($value)
217217
{
218+
if ($value instanceof Stringable) {
219+
$value = $value->toString();
220+
}
221+
218222
return $this->value === $value;
219223
}
220224

tests/Support/SupportStringableTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,4 +999,15 @@ public function testGet()
999999
$this->assertSame('foo', $this->stringable('foo')->value());
10001000
$this->assertSame('foo', $this->stringable('foo')->toString());
10011001
}
1002+
1003+
public function testExactly()
1004+
{
1005+
$this->assertTrue($this->stringable('foo')->exactly($this->stringable('foo')));
1006+
$this->assertTrue($this->stringable('foo')->exactly('foo'));
1007+
1008+
$this->assertFalse($this->stringable('Foo')->exactly($this->stringable('foo')));
1009+
$this->assertFalse($this->stringable('Foo')->exactly('foo'));
1010+
$this->assertFalse($this->stringable('[]')->exactly([]));
1011+
$this->assertFalse($this->stringable('0')->exactly(0));
1012+
}
10021013
}

0 commit comments

Comments
 (0)