Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,44 @@ public static function notSame(mixed $expected, mixed $actual, string $message =
));
}

/**
* Asserts that the condition is true.
*
* @param bool $condition The condition asserting to be true.
* @param string $message Short description about what exactly is being asserted.
* @throws AssertException when the assertion fails.
*/
public static function true(bool $condition, string $message = ''): void
{
$condition === true
? StaticState::log('Assert true', $message)
: StaticState::fail(AssertException::compare(
true,
$condition,
$message,
'Failed asserting that value `%2$s` is `%1$s`.',
));
}

/**
* Asserts that the condition is false.
*
* @param bool $condition The condition asserting to be false.
* @param string $message Short description about what exactly is being asserted.
* @throws AssertException when the assertion fails.
*/
public static function false(bool $condition, string $message = ''): void
{
$condition === false
? StaticState::log('Assert false', $message)
: StaticState::fail(AssertException::compare(
false,
$condition,
$message,
'Failed asserting that value `%2$s` is `%1$s`.',
));
}

/**
* Asserts that the given value is null.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Testo/AsserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function simpleAssertions(): void
Assert::same(1, 1);
Assert::null(null);
Assert::notSame(42, '42');
Assert::true(true);
Assert::false(false);
}

#[Test]
Expand Down