diff --git a/src/Rules/Challenge.php b/src/Rules/Challenge.php index 1d11da8..f08ff6e 100644 --- a/src/Rules/Challenge.php +++ b/src/Rules/Challenge.php @@ -8,6 +8,7 @@ class Challenge extends Rule { public const TYPE_CAPTCHA = 'captcha'; public const TYPE_CUSTOM = 'custom'; + public const TYPE_COMPUTE = 'compute'; private string $type; @@ -17,7 +18,7 @@ class Challenge extends Rule public function __construct(array $conditions = [], string $type = self::TYPE_CAPTCHA) { parent::__construct($conditions); - if (!in_array($type, [self::TYPE_CAPTCHA, self::TYPE_CUSTOM], true)) { + if (!in_array($type, [self::TYPE_CAPTCHA, self::TYPE_CUSTOM, self::TYPE_COMPUTE], true)) { throw new \InvalidArgumentException('Invalid challenge type: ' . $type); } $this->type = $type; diff --git a/tests/RulesTest.php b/tests/RulesTest.php index 4b848d5..25655ee 100644 --- a/tests/RulesTest.php +++ b/tests/RulesTest.php @@ -36,10 +36,18 @@ public function testChallengeRuleTypeDefaults(): void { $defaultRule = new Challenge(); $customRule = new Challenge([], Challenge::TYPE_CUSTOM); + $computeRule = new Challenge([], Challenge::TYPE_COMPUTE); $this->assertSame('challenge', $defaultRule->getAction()); $this->assertSame(Challenge::TYPE_CAPTCHA, $defaultRule->getType()); $this->assertSame(Challenge::TYPE_CUSTOM, $customRule->getType()); + $this->assertSame(Challenge::TYPE_COMPUTE, $computeRule->getType()); + } + + public function testChallengeRuleRejectsUnknownType(): void + { + $this->expectException(\InvalidArgumentException::class); + new Challenge([], 'not-a-real-type'); } public function testRateLimitMetadata(): void