diff --git a/src/Assert.php b/src/Assert.php index 342dc18..c5b954f 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -26,7 +26,28 @@ public static function same(mixed $expected, mixed $actual, string $message = '' { $actual === $expected ? StaticState::log('Assert same: `' . Support::stringify($expected) . '`', $message) - : StaticState::fail(AssertException::same($expected, $actual, $message)); + : StaticState::fail(AssertException::compare($expected, $actual, $message)); + } + + /** + * Asserts that two values are the not same (not identical). + * + * @param mixed $expected The expected value. + * @param mixed $actual The actual value to compare against the expected value. + * @param string $message Short description about what exactly is being asserted. + * @throws AssertException when the assertion fails. + */ + public static function notSame(mixed $expected, mixed $actual, string $message = ''): void + { + $actual !== $expected + ? StaticState::log('Assert not same: `' . Support::stringify($expected) . '`', $message) + : StaticState::fail(AssertException::compare( + $expected, + $actual, + $message, + pattern: 'Failed asserting that `%s` is not identical to `%s`.', + showDiff: false, + )); } /** @@ -42,7 +63,7 @@ public static function null( ): void { $actual === null ? StaticState::log('Assert null', $message) - : StaticState::fail(AssertException::same(null, $actual, $message)); + : StaticState::fail(AssertException::compare(null, $actual, $message)); } /** diff --git a/src/Assert/State/AssertException.php b/src/Assert/State/AssertException.php index ab0ac31..25a6f29 100644 --- a/src/Assert/State/AssertException.php +++ b/src/Assert/State/AssertException.php @@ -25,17 +25,20 @@ final protected function __construct( } /** - * Failed `same` assertion factory. + * Failed comparison assertion factory. + * * @param mixed $expected The expected value. * @param mixed $actual The actual value to compare against the expected value. * @param non-empty-string $message Short description about what exactly is being asserted. * @param non-empty-string $pattern The message pattern. + * @param bool $showDiff Whether to generate a diff between expected and actual values. */ - public static function same( + public static function compare( mixed $expected, mixed $actual, string $message, string $pattern = 'Expected `%1$s`, got `%2$s.`', + bool $showDiff = true, ): self { # todo $diff = ''; diff --git a/tests/Testo/AsserTest.php b/tests/Testo/AsserTest.php index 77cff22..58ef16a 100644 --- a/tests/Testo/AsserTest.php +++ b/tests/Testo/AsserTest.php @@ -16,6 +16,7 @@ public function simpleAssertions(): void { Assert::same(1, 1); Assert::null(null); + Assert::notSame(42, '42'); } #[Test]