Skip to content

Commit

Permalink
- Rename assure => assertion
Browse files Browse the repository at this point in the history
 - Deprecate assure. assure will be removed in v2
  • Loading branch information
Dgame committed Nov 23, 2017
1 parent 166cadd commit 47cbf37
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
18 changes: 13 additions & 5 deletions tests/AssuranceTest.php → tests/AssertionTest.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
<?php

use PHPUnit\Framework\TestCase;
use function Dgame\Ensurance\assertion;
use function Dgame\Ensurance\assure;

/**
* Class Assurance
* Class AssertionTest
*/
final class AssuranceTest extends TestCase
final class AssertionTest extends TestCase
{
public function testNegativeAssuranceWithoutMessage()
{
$this->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);
}
}

0 comments on commit 47cbf37

Please sign in to comment.