DatabaseTransactions, DatabaseMigrations have no effect.
I have the following test class
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ProvidersTest extends TestCase
{
use DatabaseMigrations;
/**
* @var \Orka\Entities\User
*/
protected $user;
/**
* @var \Orka\Entities\Team
*/
protected $team;
public function setUp()
{
parent::setUp();
$team = factory(\Orka\Entities\Team::class)->create();
$user = factory(\Orka\Entities\User::class)->create();
$user->attachTeam($team);
$this->user = $user;
$this->team = $team;
}
/**
* @test
*/
public function it_shows_no_connected_providers()
{
$this
->actingAs($this->user)
->visit('/teams/1/providers')
->see('You have not connected a provider yet.')
;
}
}
When running this code I get an error telling me tables do no exist, the only way I can get it to work is to call $this->runDatabaseMigrations(); in the setUp method, but as far as I know I should not need to do that. I have similar issues with DatabaseTransactions.
I believe I am having a similar problem. I'm using the DatabaseMigrations trait. If my test implements it's own setUp method, then traits do not work. If I remove the setup method traits work again.
It seems to be resolved by manually calling the trait method from within my setup method, but as for why the traits stop working when a setup method is implemented, I have no idea :(
Hey guys. We got this fixed, but it hasn't been tagged yet (I don't think).
The issue is that PHPUnit's "before" methods aren't triggered until after your setup method. So that means your database transactions aren't initialized until after your factories. That's why things weren't working.
Thanks Jeffrey. Your fix hasn't been rolled into Laravel 5.1, however, so this is still an issue there. I commented on Taylor's commit, so hopefully he'll notice and make the changes.
@johnberberich I have just run across the same issue in Laravel 5.1. Since it doesn't seem to have been fixed, I have created a pull request, hoping it will get merged.