From 47cbf37e9dbcfde39ff5ba6eb75d633a817aa64e Mon Sep 17 00:00:00 2001 From: Dgame Date: Thu, 23 Nov 2017 11:20:06 +0100 Subject: [PATCH] - Rename assure => assertion - Deprecate assure. assure will be removed in v2 --- src/functions.php | 14 +++++++++++++- tests/{AssuranceTest.php => AssertionTest.php} | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) rename tests/{AssuranceTest.php => AssertionTest.php} (59%) diff --git a/src/functions.php b/src/functions.php index f418d4c..9bc8849 100644 --- a/src/functions.php +++ b/src/functions.php @@ -31,9 +31,21 @@ function enforce(bool $condition, string $message = null): Enforcement * * @throws \AssertionError */ -function assure(bool $condition, string $message = null) +function assertion(bool $condition, string $message = null) { if (!$condition) { throw new \AssertionError($message ?? 'Assertion failed'); } +} + +/** + * @param bool $condition + * @param string|null $message + * + * @throws \AssertionError + * @deprecated Use assertion instead. `assure` is just an alias for `assertion`, since `assertion` is a more meaningful name. + */ +function assure(bool $condition, string $message = null) +{ + assertion($condition, $message); } \ No newline at end of file diff --git a/tests/AssuranceTest.php b/tests/AssertionTest.php similarity index 59% rename from tests/AssuranceTest.php rename to tests/AssertionTest.php index b106a01..c16002f 100644 --- a/tests/AssuranceTest.php +++ b/tests/AssertionTest.php @@ -1,29 +1,37 @@ expectException(AssertionError::class); $this->expectExceptionMessage('Assertion failed'); - assure(0); + assertion(0); } public function testNegativeAssuranceWithMessage() { $this->expectException(AssertionError::class); $this->expectExceptionMessage('That went wrong'); - assure(0, 'That went wrong'); + assertion(0, 'That went wrong'); } public function testPositiveAssurance() { - assure(true); + assertion(true); + } + + public function testDeprecatedAssurance() + { + $this->expectException(AssertionError::class); + $this->expectExceptionMessage('Assertion failed'); + assure(0); } } \ No newline at end of file