Files
esun3d/app/code/Esun/FreeGift/Test/Unit/Model/InternalAddGuardTest.php
T
2026-09-15 10:35:56 +08:00

33 lines
876 B
PHP

<?php
declare(strict_types=1);
namespace Esun\FreeGift\Test\Unit\Model;
use Esun\FreeGift\Model\InternalAddGuard;
use PHPUnit\Framework\TestCase;
class InternalAddGuardTest extends TestCase
{
public function testExecuteAllowsOnlyTheWrappedCallback(): void
{
$guard = new InternalAddGuard();
self::assertFalse($guard->isAllowed());
self::assertTrue($guard->execute(static fn (): bool => $guard->isAllowed()));
self::assertFalse($guard->isAllowed());
}
public function testGuardIsResetWhenCallbackThrows(): void
{
$guard = new InternalAddGuard();
try {
$guard->execute(static function (): void {
throw new \RuntimeException('Expected test exception');
});
} catch (\RuntimeException) {
self::assertFalse($guard->isAllowed());
}
}
}