Chron's avatar

Precognition and Testing

Any reasons why it doesn't hit Controller even if the fields passed the validation?

Test

public function test_it_records_todo(): void {

	$response = $this->withPrecognition()->post(route('todo.store'), [
		'name' => 'Test ToDo',
	]);
    $response->assertSuccessfulPrecognition();


    $response = $this->post(route('todo.store'), [
		'name' => 'Test ToDo',
	]);
    $response->assertSuccessful();
}

Controller

TodoController

public function store(StoreTodoRequest $request) {
	dd('hit');
	//...
}

StoreTodoRequest

public function rules(): array {
        return [
            'name' => 'required',
        ];
    }

Do I need to separate them instead?

0 likes
1 reply
martinbean's avatar
Level 80

@chron You should not be performing multiple requests in a single test case like that.

1 like

Please or to participate in this conversation.