From dfcdaa3f8e4561db0b08f1d72593732d50ab7b66 Mon Sep 17 00:00:00 2001 From: Thai Nguyen Hung Date: Tue, 22 Aug 2023 11:10:25 +0700 Subject: [PATCH] feat: `toHaveSameSize` expectation --- src/Mixins/Expectation.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 6b69014b..57040711 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -6,6 +6,7 @@ namespace Pest\Mixins; use BadMethodCallException; use Closure; +use Countable; use DateTimeInterface; use Error; use InvalidArgumentException; @@ -272,6 +273,22 @@ final class Expectation return $this; } + /** + * Asserts that the size of the value and $expected are the same. + * + * @return self + */ + public function toHaveSameSize(Countable|iterable $expected, string $message = ''): self + { + if (! is_countable($this->value) && ! is_iterable($this->value)) { + InvalidExpectationValue::expected('countable|iterable'); + } + + Assert::assertSameSize($expected, $this->value, $message); + + return $this; + } + /** * Asserts that the value contains the property $name. *