Add toBeFalsy

This commit is contained in:
Esteban
2021-08-03 20:55:07 -04:00
parent cffde4564d
commit 8ee07330b3
2 changed files with 36 additions and 0 deletions

View File

@ -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.
*

View File

@ -0,0 +1,26 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('passes', function () {
expect(false)->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);