.
This commit is contained in:
commit
a5ce423afe
30 changed files with 1807 additions and 0 deletions
58
tests/AspectExceptionTest.php
Normal file
58
tests/AspectExceptionTest.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
use IceFox\Aspect\AspectException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Aspects\ThrowingAspect;
|
||||
use Tests\Classes\ThrowingClass;
|
||||
|
||||
final class AspectExceptionTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
ThrowingAspect::reset();
|
||||
}
|
||||
|
||||
public function testExceptionInBeforeIsWrappedInAspectException(): void
|
||||
{
|
||||
ThrowingAspect::$throwInBefore = true;
|
||||
|
||||
$instance = new ThrowingClass();
|
||||
|
||||
try {
|
||||
$instance->methodWithAspect();
|
||||
$this->fail('Expected AspectException to be thrown');
|
||||
} catch (AspectException $e) {
|
||||
$this->assertEquals('Exception in before() method of aspect', $e->getMessage());
|
||||
$this->assertEquals(ThrowingAspect::class, $e->aspectClass);
|
||||
$this->assertEquals('before', $e->method);
|
||||
$this->assertInstanceOf(\RuntimeException::class, $e->getPrevious());
|
||||
$this->assertEquals('Exception thrown in before()', $e->getPrevious()->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testExceptionInAfterIsWrappedInAspectException(): void
|
||||
{
|
||||
ThrowingAspect::$throwInAfter = true;
|
||||
|
||||
$instance = new ThrowingClass();
|
||||
|
||||
try {
|
||||
$instance->methodWithAspect();
|
||||
$this->fail('Expected AspectException to be thrown');
|
||||
} catch (AspectException $e) {
|
||||
$this->assertEquals('Exception in after() method of aspect', $e->getMessage());
|
||||
$this->assertEquals(ThrowingAspect::class, $e->aspectClass);
|
||||
$this->assertEquals('after', $e->method);
|
||||
$this->assertInstanceOf(\RuntimeException::class, $e->getPrevious());
|
||||
$this->assertEquals('Exception thrown in after()', $e->getPrevious()->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testMethodExecutesSuccessfullyWhenNoExceptions(): void
|
||||
{
|
||||
$instance = new ThrowingClass();
|
||||
$result = $instance->methodWithAspect();
|
||||
|
||||
$this->assertEquals('success', $result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue