Laravel phpunit DB::rollback in tearDownAfterClass

Viewed 367

I want to build a functionality/integration test for my messaging system in the API so that methods can depend upon each other. For that reason I don't want to use DatabaseTransactions trait, as it rolls back the transaction after each method.

So I came up with the following solution:

public static function setUpBeforeClass()
{
    \DB::beginTransaction();
}

and

public static function tearDownAfterClass()
{
    \DB::rollBack();
}

This unfortunately gives me the following error:

  [Symfony\Component\Debug\Exception\FatalErrorException]             
  Call to undefined method Illuminate\Support\Facades\DB::rollBack()

Any ideas how to roll back the transaction? Even if I make it work - is this the right way to do that?

0 Answers
Related