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

Mocking CAPTCHA #44

Open
cosmin84 opened this issue Apr 6, 2020 · 1 comment
Open

Mocking CAPTCHA #44

cosmin84 opened this issue Apr 6, 2020 · 1 comment

Comments

@cosmin84
Copy link

cosmin84 commented Apr 6, 2020

Hello,
Is there any way to mock the CAPTCHA in an unit for feature test?
Thanks!

@ismaail
Copy link

ismaail commented Oct 2, 2020

My solution, forcing the captcha validation rule to just return true:

public function testSomething()
{
    $this->mockValidatorExtension(config('bone.captcha.validator'), function () { return true; });

    //.......
}

/**
 * @param string $rule
 * @param \Closure|string $extensionStub
 */
private function mockValidatorExtension($rule, $extensionStub)
{
    $validator = $this->app->get('validator');

    $reflection = new ReflectionClass($validator);
    $property = $reflection->getProperty('extensions');
    $property->setAccessible(true);

    $extensions = $property->getValue($validator);

    $extensions[$rule] = $extensionStub;

    $property->setValue($validator, $extensions);
}

credits: https://github.com/framgia/laravel-test-guideline/blob/master/en/Unit/Validation.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants