Merge pull request #924 from hungthai1401/to_have_same_size_expectation

[2.x] Add `toHaveSameSize` expectation
This commit is contained in:
Nuno Maduro
2023-08-23 10:14:17 +01:00
committed by GitHub
2 changed files with 41 additions and 0 deletions

View File

@ -272,6 +272,23 @@ final class Expectation
return $this;
}
/**
* Asserts that the size of the value and $expected are the same.
*
* @param array<int|string, mixed> $expected
* @return self<TValue>
*/
public function toHaveSameSize(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.
*