From 19dee2d3b780cb5f4a7fab2a402fcb1b3ce3a3d2 Mon Sep 17 00:00:00 2001 From: Petr Dobrokhotov Date: Sat, 25 Oct 2025 21:45:13 +0200 Subject: [PATCH 1/2] feat(assert): Add Assert::true --- src/Assert.php | 19 +++++++++++++++++++ tests/Testo/AsserTest.php | 1 + 2 files changed, 20 insertions(+) diff --git a/src/Assert.php b/src/Assert.php index c5b954f..23d4525 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -50,6 +50,25 @@ 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 given value is null. * diff --git a/tests/Testo/AsserTest.php b/tests/Testo/AsserTest.php index 58ef16a..5415d5c 100644 --- a/tests/Testo/AsserTest.php +++ b/tests/Testo/AsserTest.php @@ -17,6 +17,7 @@ public function simpleAssertions(): void Assert::same(1, 1); Assert::null(null); Assert::notSame(42, '42'); + Assert::true(true); } #[Test] From 76b0679bbe8554a341112b2432e5d61d105d3cf8 Mon Sep 17 00:00:00 2001 From: Petr Dobrokhotov Date: Sat, 25 Oct 2025 22:30:13 +0200 Subject: [PATCH 2/2] feat(assert): Add `Assert::false` --- src/Assert.php | 19 +++++++++++++++++++ tests/Testo/AsserTest.php | 1 + 2 files changed, 20 insertions(+) diff --git a/src/Assert.php b/src/Assert.php index 23d4525..2a86f93 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -69,6 +69,25 @@ public static function true(bool $condition, string $message = ''): void )); } + /** + * 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. * diff --git a/tests/Testo/AsserTest.php b/tests/Testo/AsserTest.php index 5415d5c..e7e5212 100644 --- a/tests/Testo/AsserTest.php +++ b/tests/Testo/AsserTest.php @@ -18,6 +18,7 @@ public function simpleAssertions(): void Assert::null(null); Assert::notSame(42, '42'); Assert::true(true); + Assert::false(false); } #[Test]