D9705996's avatar

Use a different Database for a single Test?

I have the following test setup that tries to add an entry to a model and when I run the following test with the sqlite in-memory database everything passes.

        $this->json('POST', 'api/v1/authentications/ssh/credentials', [
            'username' => 'root',
            'password' => 'goofFnBfo9mi0Y',
            'description' => 'test'
        ])->assertStatus(Response::HTTP_CREATED);

However when I try to replicate the test with the production API I get a "Data too long for column" error from MySQL because the password value is being encrypted and is longer that the 191 character limit on the field.

I am going to change the column type to fix the problem but I really want to make the test fail first so I know that it is really fixed.

Is it possible to configure this single test to override the default database to use a MySQL database?

0 likes
2 replies
D9705996's avatar

@jlrdw - Prefect Thank you. I added DB::connection('mysql'); at the top of the affected test.

Please or to participate in this conversation.