From 8ee07330b361b0a7e142d52e85cd67afac1e292b Mon Sep 17 00:00:00 2001 From: Esteban Date: Tue, 3 Aug 2021 20:55:07 -0400 Subject: [PATCH] Add toBeFalsy --- src/Expectation.php | 10 ++++++++++ tests/Features/Expect/ToBeFalsy.php | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/Features/Expect/ToBeFalsy.php diff --git a/src/Expectation.php b/src/Expectation.php index 9c81ab04..fabc51f8 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -225,6 +225,16 @@ final class Expectation return $this; } + /** + * Asserts that the value is falsy. + */ + public function toBeFalsy(): Expectation + { + Assert::assertFalse((bool) $this->value); + + return $this; + } + /** * Asserts that the value is greater than $expected. * diff --git a/tests/Features/Expect/ToBeFalsy.php b/tests/Features/Expect/ToBeFalsy.php new file mode 100644 index 00000000..761e9cc1 --- /dev/null +++ b/tests/Features/Expect/ToBeFalsy.php @@ -0,0 +1,26 @@ +toBeFalsy(); + expect('')->toBeFalsy(); + expect(null)->toBeFalsy(); + expect([])->toBeFalsy(); + expect(0)->toBeFalsy(); + expect('0')->toBeFalsy(); + + expect(true)->not->toBeFalsy(); + expect([1])->not->toBeFalsy(); + expect('false')->not->toBeFalsy(); + expect(1)->not->toBeFalsy(); + expect(-1)->not->toBeFalsy(); +}); + +test('failures', function () { + expect(1)->toBeFalsy(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(null)->not->toBeFalsy(); +})->throws(ExpectationFailedException::class);