samedi 4 août 2018

Some tests started failing when using conn:sqlite value::memory: instead of conn:mysql db:testing in phpunit.xml?

I have already written many tests. All were passing in this config of phpunit.xml

<env name="DB_CONNECTION" value="mysql"/>
<env name="DB_DATABASE" value="testing"/>

But they were slow so I changed it to in-memory sqlite:

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

This is very fast but gives error on some tests.

example:

/** @test */
public function a_user_can_create_a_post()
{

  $payload = [
     'title' => 'This is title',
     'body' => 'This is body',
  ];

        $this->actingAs($this->adminUser)
                        ->json('POST', '/post', $payload)
                        ->assertRedirect(route('post.index'))
                        ->assertSessionHas('message', 'Post Created!');
}

I don't understand the reason for this. This test works correctly in mysql config.

What is the problem ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire