aspect/tests/Aspects/ThrowingAspect.php
2026-01-07 12:06:14 -03:00

40 lines
865 B
PHP

<?php
namespace Tests\Aspects;
use Attribute;
use IceFox\Aspect\AspectContext;
use RuntimeException;
#[Attribute(Attribute::TARGET_METHOD)]
class ThrowingAspect
{
public static bool $throwInBefore = false;
public static bool $throwInAfter = false;
public function __construct(
private readonly AspectContext $context,
) {
}
public function before(array $args): void
{
if (self::$throwInBefore) {
throw new RuntimeException('Exception thrown in before()');
}
}
public function after(mixed $result): mixed
{
if (self::$throwInAfter) {
throw new RuntimeException('Exception thrown in after()');
}
return $result;
}
public static function reset(): void
{
self::$throwInBefore = false;
self::$throwInAfter = false;
}
}