D
D
Denis2021-02-10 21:40:00
PHPUnit
Denis, 2021-02-10 21:40:00

Testing in Laravel?

I'm trying to get acquainted with tests in Laravel 8. I'm writing a simple test

public function testStore()
    {
        $data = [
            'name' => 'https://test.ru'
        ];
        $response = $this->post(route('urls.store'), $data);
        $response->assertSessionHasNoErrors();
        $response->assertRedirect();
        $this->assertDatabaseHas('urls', $data);
    }

answer: status code 500, I don’t understand why?
I thought because of the token, I added it to the request, but it did not help. Yes, and get tests pass norms like this
$response = $this->get(route('urls.index'));
        $response->assertOk();


I looked at the logs, complains that in Validator::make (make is just the first in the store to accept the request), null comes in, but I seem to be passing the data to $data? Tell me what's wrong? I'm confused)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question