C
C
chubaroid2022-04-10 01:49:51
PHP
chubaroid, 2022-04-10 01:49:51

How to disable automatic database cleaning in Laravel during testing?

I have a feature test to test the registration and authorization mechanism. There are 2 methods in the test class. The first method checks registration, writes data to the database. The second method performs authorization. But for the second method to work, you need to re-register inside this method. How to make sure that after the execution of the first method, the database is not cleared from the previous test, and the second test is already working with the data in the database that was recorded in the previous test?

If I'm not doing the check at all, please point me in the right direction) I'm just learning!

/**
     * Проверка системы регистрации
     * @test
     */
    public function registration()
    {
        $this->get('/registration')->assertStatus(200);

        $response = $this->post('/registration', ['email' => $this->email, 'password' => $this->password]);

        $response->assertRedirect('/login');

        $this->assertDatabaseHas('users',  ['email' => $this->email]);

    }

    /**
     * Проверка системы авторизации
     * @test
     */
    public function login() // для работы этого теста приходится снова в это методе прописывать регистрацию
    {
        $this->get('/login')->assertStatus(200);

        $response = $this->post('/login', ['email' => $this->email, 'password' => $this->password]);

        $response->assertRedirect('/');

        $this->assertAuthenticated();
    }

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