From df2113a1cc60b14ec3438366d9ac9e37e2375f2c Mon Sep 17 00:00:00 2001 From: Rahul Mac Date: Sat, 22 Nov 2025 09:51:41 +0530 Subject: [PATCH 1/2] feat: allow any \Stringable implementation for Stringable::exactly() --- src/Illuminate/Support/Stringable.php | 6 +++--- tests/Support/SupportStringableTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 67c4b9b5ddd5..89315546fc88 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -293,13 +293,13 @@ public function doesntEndWith($needles) /** * Determine if the string is an exact match with the given value. * - * @param \Illuminate\Support\Stringable|string $value + * @param BaseStringable|string $value * @return bool */ public function exactly($value) { - if ($value instanceof Stringable) { - $value = $value->toString(); + if ($value instanceof BaseStringable) { + $value = (string) $value; } return $this->value === $value; diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 56dd427dd1da..37d9d80014cb 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -1477,6 +1477,13 @@ public function testExactly() $this->assertFalse($this->stringable('Foo')->exactly('foo')); $this->assertFalse($this->stringable('[]')->exactly([])); $this->assertFalse($this->stringable('0')->exactly(0)); + $this->assertTrue($this->stringable('foo')->exactly(new class () implements \Stringable { + public function __toString(): string + { + return 'foo'; + } + })); + $this->assertFalse($this->stringable('foo')->exactly(new class () {})); } public function testToInteger() From eb571818edbc2f9552186b59cd3bdfda0630402e Mon Sep 17 00:00:00 2001 From: Rahul Mac Date: Sat, 22 Nov 2025 10:13:22 +0530 Subject: [PATCH 2/2] refactor: style fixes --- tests/Support/SupportStringableTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 37d9d80014cb..ce0d2e2c4c4b 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -1477,13 +1477,14 @@ public function testExactly() $this->assertFalse($this->stringable('Foo')->exactly('foo')); $this->assertFalse($this->stringable('[]')->exactly([])); $this->assertFalse($this->stringable('0')->exactly(0)); - $this->assertTrue($this->stringable('foo')->exactly(new class () implements \Stringable { + $this->assertTrue($this->stringable('foo')->exactly(new class() implements \Stringable + { public function __toString(): string { return 'foo'; } })); - $this->assertFalse($this->stringable('foo')->exactly(new class () {})); + $this->assertFalse($this->stringable('foo')->exactly(new class() {})); } public function testToInteger()