mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Added toBeList expectation
This commit is contained in:
@ -467,6 +467,18 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is a list.
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeList(string $message = ''): self
|
||||
{
|
||||
Assert::assertIsList($this->value, $message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is of type bool.
|
||||
*
|
||||
|
||||
20
tests/Features/Expect/toBeList.php
Normal file
20
tests/Features/Expect/toBeList.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([1, 2, 3])->toBeList();
|
||||
expect(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeList();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeList('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(['a', 'b', 'c'])->not->toBeList();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
Reference in New Issue
Block a user