Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proper fake on the facade #12

Open
RVxLab opened this issue Jan 23, 2023 · 0 comments
Open

Add a proper fake on the facade #12

RVxLab opened this issue Jan 23, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@RVxLab
Copy link
Owner

RVxLab commented Jan 23, 2023

Instead of needing to manually mock the display and verify calls, it's nice to be able to just call HCaptcha::fake() and have it automatically set some reasonable defaults.

This will require the introduction of a contract:

interface HCaptchaContract
{
    public function display(array $attributes = []): string;

    public function displayWidget(array $attributes = []): string;

    public function displaySubmit(string $formIdentifier, string $buttonText = 'submit', array $attributes = []): string;

    public function renderJs(?string $lang = null, bool $hasCallback = false, string $onLoadClass = 'onloadCallBack'): string;

    public function verifyResponse(string $response, ?string $clientIp = null): bool;

    public function verifyRequest(Request $request): bool;

    public function getJsLink(?string $lang = null, bool $hasCallback = false, string $onLoadClass = 'onloadCallBack'): string;
}

For the fake, any of the display methods can return an input with any value, so it can be rendered and form validation will succeed.

The getJsLink method can just return an empty string, that's not really important here.

The verify methods should return true by default with the option to mock that call as needed by means of a shouldVerify(bool) or a successfullyVerifies() and failsVerification() pair.

@RVxLab RVxLab added the enhancement New feature or request label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant