sanjitsingh's avatar

RefreshDatabase not rolling back the transaction after running test

Hi there,

I am using mysql as a testing database. I am trying to rollback the changes after each test using RefreshDatabase trait but it is not working.

    use RefreshDatabase;

    protected $connectionsToTransact = [
        'mysql_testing'
    ];

    /** @test */
    public function user_can_add_custom_field()
    {
        $this->signIn();

        $attributes = [
            'name' => 'Make',
            'type' => 'text'
        ];

        $response = $this->postJson('/api/custom-fields', $attributes);

        $response->assertStatus(201);
        $this->assertDatabaseHas('mrp_custom_fields', $attributes);
    }

My MySql engine is InnoDB. After running this test. I am still seeing the record in mysql database.

0 likes
2 replies
Bahjaat's avatar

it is bugging me too. For the time being I am using 'DatabaseMigrations'.

mware's avatar

Try using 'DatabaseTransactions'.

    use DatabaseTransactions;

Also, is there a reason why you are setting your testing database connection in the phpunit.xml file?

Please or to participate in this conversation.