Laravel DatabaseTruncation exceptTables still truncated

183 views Asked by At

I have a laravel project with a Dusk setup.

From the docs, to keep the database clean for tests, we should use DatabaseTruncation trait.

In my case, the trait works, but when I set a parameter $exceptTables = ['table1', 'table2'], they still get truncated whereas they shouldn't.

When using the parameter $tablesToTruncate = ['table1'], it works correctly.

I could put all the tables in this second parameter, but it would be cleaner to just specify the few ones I mustn't truncate.

Anyone has seen this before?

1

There are 1 answers

2
Cameron Wilby On

Reading the DatabaseTruncation trait here, $exceptTables should be grouped by connection name as shown, and $connectionsToTruncate should be present.

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;
    use DatabaseTruncation;

    protected $connectionsToTruncate = [
      'mysql_testing'
    ];

    protected $exceptTables = [
        'mysql_testing' => [
            'table1',
            'table2'
        ]
    ];
}

I submitted a pull request to Laravel 10 to support an array of table names without the connection key: https://github.com/laravel/framework/pull/47477