mirror of
https://github.com/pestphp/pest.git
synced 2026-03-13 19:27:22 +01:00
Merge pull request #923 from hungthai1401/inconsistent_type_have_count_exception
[2.x] Inconsistent type have count exception
This commit is contained in:
@ -264,7 +264,7 @@ final class Expectation
|
|||||||
public function toHaveCount(int $count, string $message = ''): self
|
public function toHaveCount(int $count, string $message = ''): self
|
||||||
{
|
{
|
||||||
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('countable|iterable');
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert::assertCount($count, $this->value, $message);
|
Assert::assertCount($count, $this->value, $message);
|
||||||
|
|||||||
@ -1,11 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Pest\Exceptions\InvalidExpectationValue;
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
expect([1, 2, 3])->toHaveCount(3);
|
expect([1, 2, 3])->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 () {
|
test('failures', function () {
|
||||||
expect([1, 2, 3])->toHaveCount(4);
|
expect([1, 2, 3])->toHaveCount(4);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user