-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f638247
commit f1da0d7
Showing
8 changed files
with
358 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
verbose="true"> | ||
<testsuites> | ||
<testsuite name="devlop/phpunit-exception-assertions Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Devlop\PHPUnit\Tests; | ||
|
||
use Devlop\PHPUnit\ExceptionAssertions; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AssertExceptionNotThrownTest extends TestCase | ||
{ | ||
use ExceptionAssertions; | ||
|
||
function test_assert_exception_not_thrown_does_not_pass_if_the_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionNotThrown(\RuntimeException::class, function () : void { | ||
throw new \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertFalse($assertionPasses); | ||
} | ||
|
||
function test_assert_exception_not_thrown_does_not_pass_if_parent_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionNotThrown(\Throwable::class, function () : void { | ||
throw \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertFalse($assertionPasses); | ||
} | ||
|
||
function test_assert_exception_not_thrown_passes_if_no_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionNotThrown(\RuntimeException::class, function () : void { | ||
// do nothing | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertTrue($assertionPasses); | ||
} | ||
|
||
function test_assert_exception_not_thrown_passes_if_another_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionNotThrown(\InvalidArgumentException::class, function () : void { | ||
throw new \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertTrue($assertionPasses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Devlop\PHPUnit\Tests; | ||
|
||
use Devlop\PHPUnit\ExceptionAssertions; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AssertExceptionThrownTest extends TestCase | ||
{ | ||
use ExceptionAssertions; | ||
|
||
function test_assert_exception_thrown_does_not_pass_if_no_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionThrown(\Throwable::class, function () : void { | ||
// do nothing | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertFalse($assertionPasses); | ||
} | ||
|
||
function test_assert_exception_thrown_does_not_pass_if_another_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionThrown(\InvalidArgumentException::class, function () : void { | ||
throw new \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertFalse($assertionPasses); | ||
} | ||
|
||
function test_assert_exception_thrown_passes_if_the_correct_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionThrown(\RuntimeException::class, function () : void { | ||
throw new \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertTrue($assertionPasses); | ||
} | ||
|
||
function test_assert_exception_thrown_passes_if_parent_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertExceptionThrown(\Throwable::class, function () : void { | ||
throw new \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertTrue($assertionPasses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Devlop\PHPUnit\Tests; | ||
|
||
use Devlop\PHPUnit\ExceptionAssertions; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AssertNoExceptionsThrownTest extends TestCase | ||
{ | ||
use ExceptionAssertions; | ||
|
||
function test_assert_no_exceptions_thrown_does_not_pass_if_any_exception_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertNoExceptionsThrown(function () : void { | ||
throw new \RuntimeException('Oh?'); | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertFalse($assertionPasses); | ||
} | ||
|
||
function test_assert_no_exceptions_thrown_passes_if_no_exceptions_was_thrown() : void | ||
{ | ||
$assertionPasses = true; | ||
|
||
try { | ||
$this->assertNoExceptionsThrown(function () : void { | ||
// do nothing | ||
}); | ||
} catch (\PHPUnit\Framework\Exception $exception) { | ||
$assertionPasses = false; | ||
} | ||
|
||
$this->assertTrue($assertionPasses); | ||
} | ||
} |
Oops, something went wrong.