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
25 changes: 23 additions & 2 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
}

/**
Expand All @@ -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));
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Assert/State/AssertException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
1 change: 1 addition & 0 deletions tests/Testo/AsserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function simpleAssertions(): void
{
Assert::same(1, 1);
Assert::null(null);
Assert::notSame(42, '42');
}

#[Test]
Expand Down