Skip to content

Commit

Permalink
Merge pull request #5 from kiddivouchers/testing-improvements
Browse files Browse the repository at this point in the history
Testing improvements
  • Loading branch information
cs278 authored Aug 29, 2024
2 parents e0273a8 + a604fc9 commit a8c722e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ public function __construct(
}
}

/**
* Create instance representing a success.
*/
public static function success(?\DateTimeImmutable $challengeTime = null, ?string $hostname = null): self
{
return new self(
true,
[],
$challengeTime,
$hostname,
);
}

/**
* Create instance representing a failure.
*
* @param list<ErrorCode>&non-empty-array $errorCodes
*/
public static function failure(array $errorCodes, ?\DateTimeImmutable $challengeTime = null, ?string $hostname = null): self
{
Assert::minCount($errorCodes, 1);

return new self(
false,
$errorCodes,
$challengeTime,
$hostname,
);
}

public static function fromJson(string $json): self
{
try {
Expand Down
5 changes: 4 additions & 1 deletion src/TestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function verify(string $response, ?string $siteKey = null, ?string $remot
return $this->seen[$response];
}

throw new \RuntimeException('No response found');
throw new \RuntimeException(sprintf(
'No result found for response `%s`',
$response,
));
}
}

0 comments on commit a8c722e

Please sign in to comment.