From 60b615ea6af5ec9de546c928158f910a0fcebf08 Mon Sep 17 00:00:00 2001 From: Thai Nguyen Hung Date: Tue, 22 Aug 2023 10:35:07 +0700 Subject: [PATCH 1/2] fix: inconsistent type in `InvalidExpectationValue` exception at `toHaveCount` expectation --- src/Mixins/Expectation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 6b69014b..303a3965 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -264,7 +264,7 @@ final class Expectation public function toHaveCount(int $count, string $message = ''): self { if (! is_countable($this->value) && ! is_iterable($this->value)) { - InvalidExpectationValue::expected('string'); + InvalidExpectationValue::expected('countable|iterable'); } Assert::assertCount($count, $this->value, $message); From 79bc9e677ffb13d0d03558532c439307a3af23ca Mon Sep 17 00:00:00 2001 From: Thai Nguyen Hung Date: Tue, 22 Aug 2023 10:36:10 +0700 Subject: [PATCH 2/2] test: `toHaveCount` with invalid type --- tests/Features/Expect/toHaveCount.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Features/Expect/toHaveCount.php b/tests/Features/Expect/toHaveCount.php index 726f2c64..153175cf 100644 --- a/tests/Features/Expect/toHaveCount.php +++ b/tests/Features/Expect/toHaveCount.php @@ -1,11 +1,16 @@ toHaveCount(3); }); +test('failures with invalid type', function () { + expect('foo')->toHaveCount(3); +})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable]'); + test('failures', function () { expect([1, 2, 3])->toHaveCount(4); })->throws(ExpectationFailedException::class);