@iamine I use reCATPCHA in applications. I don’t disable the validation rule, though; I mock the reCAPTCHA service to return the values I want. This means I can test both successful and failed reCAPTCHA responses instead of just going, “Well, this is a test, so I’m not even going to both with this rule”.
protected function setUp(): void
{
parent::setUp();
$this->captcha = $this->mock(Captcha::class);
}
public function testCaptchaPassesWithGoodValue(): void
{
$this->captcha->shouldReceive('verify')->with('GOODVALUE')->andReturn(true);
$response = $this->post('/some-uri-that-uses-recpatcha', [
'g-recaptcha-response' => 'GOODVALUE',
]);
$response->assertSuccessful();
}
public function testCaptchaFailsWithBadValue(): void
{
$this->captcha->shouldReceive('verify')->with('BADVALUE')->andReturn(false);
$response = $this->post('/some-uri-that-uses-recpatcha', [
'g-recaptcha-response' => 'BADVALUE',
]);
$response->assertSessionHasErrors('g-recaptcha-response');
}
So, now I no longer have horrible if statements in my application code checking if it’s being ran in a test or not, and turning things on and off just for the sake of getting a test to pass.