diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 71117657..ffaeea30 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -467,6 +467,18 @@ final class Expectation return $this; } + /** + * Asserts that the value is a list. + * + * @return self + */ + public function toBeList(string $message = ''): self + { + Assert::assertIsList($this->value, $message); + + return $this; + } + /** * Asserts that the value is of type bool. * diff --git a/tests/Features/Expect/toBeList.php b/tests/Features/Expect/toBeList.php new file mode 100644 index 00000000..a10115da --- /dev/null +++ b/tests/Features/Expect/toBeList.php @@ -0,0 +1,20 @@ +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);