From 55f6b5696e946464c4c22a39c96ac7d5ce0c401f Mon Sep 17 00:00:00 2001 From: Morten Harders Date: Tue, 21 May 2024 08:13:20 +0200 Subject: [PATCH 1/2] Added toBeList expectation --- src/Mixins/Expectation.php | 12 ++++++++++++ tests/Features/Expect/toBeList.php | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/Features/Expect/toBeList.php 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); From 3c6c89a6ade4dab9884e78e77dfd49fd85af13c0 Mon Sep 17 00:00:00 2001 From: Morten Harders Date: Tue, 21 May 2024 08:15:32 +0200 Subject: [PATCH 2/2] Added test to toBeList --- tests/Features/Expect/toBeList.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Features/Expect/toBeList.php b/tests/Features/Expect/toBeList.php index a10115da..095fda9d 100644 --- a/tests/Features/Expect/toBeList.php +++ b/tests/Features/Expect/toBeList.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { expect([1, 2, 3])->toBeList(); expect(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList(); + expect('1, 2, 3')->not->toBeList(); }); test('failures', function () {