33 lines
876 B
PHP
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());
|
|
}
|
|
}
|
|
}
|