From da20a62e49180c579c1006ed56005dffe17c6b6e Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Tue, 21 Nov 2023 22:56:21 -0500 Subject: [PATCH] Add toSnapshot() early return Sometimes objects need native toString() and toArray() methods that are different from what you want to snapshot. This adds an explicit toSnapshot() method that will be called first (when set) allowing for better snapshot values than the generic methods offer. --- src/Mixins/Expectation.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index a6910b64..a9edcf07 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -844,6 +844,7 @@ final class Expectation $string = match (true) { is_string($this->value) => $this->value, + is_object($this->value) && method_exists($this->value, 'toSnapshot') => $this->value->toSnapshot(), is_object($this->value) && method_exists($this->value, '__toString') => $this->value->__toString(), is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(), $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line