Closed hamidrasti closed 3 years ago
I ended up this issue with mocking form request:
public function test_should_store_contacts_when_everything_is_ok()
{
$testInput = [
'message' => 'my_message',
'captcha' => 'test1',
];
$this->withoutExceptionHandling();
$this->mock(ContactRequest::class, function ($mock) use ($testInput) {
$mock->shouldReceive('passes')->andReturn(true);
$mock->shouldReceive('validated')->andReturn($testInput);
});
$response = $this->post(route('contacts.store'), $testInput);
$response->assertRedirect();
$this->assertDatabaseHas('contacts', [
'message' => $testInput['message'],
]);
}
@hamraa By mocking your entire request validation class, the issue is that you are not testing your other rules.
You can do that instead:
public function can_submit_a_message()
{
// Mock captcha verification
app('validator')->extend('captcha', fn () => true);
// Your test...
$form = [
'message' => 'my_message',
'captcha' => 'anything',
];
$this->post('/contact', $form)->assertOk();
}
Your captcha will always be validated.
Did someone manage to test forms with a captcha that are into a livewire component?
Hi. First of all, thanks for this great package.
Is there any way to test forms with captcha? (is there any way to generate test captcha?)
to able to write test like this: