samedi 16 mars 2019

Laravel 5.8 Testing w/ Database Must Run One at a Time

Odd behavior that could be coming from the not doing it correctly place. I'm also not sure what all information would help keep this succinct yet cover the issue - updates will be added ass necessary.

Consider a vanilla Laravel install.

// UserTest.php

class UserTest extends TestCase
{
    use RefreshDatabase;

    public function testOne()
    {
        $user = User::make(['email' => 'one@neo.com']);
        $user->save();
        $this->assertTrue($user->id == 1);
    }

    public function testTwo()
    {
        $user = User::make(['email' => 'two@wot.com']);
        $user->save();
        $this->assertTrue($user->id == 1);
    }
}

Running the tests one at a time, they both pass (phpunit --filter=testOne and phpunit --filter=testTwo). Run them sequentially, all but the first will error out with a timeout error (phpunit).

What's going on (I'd really like to understand the why)? And what's the fix?

What I've tried:

  1. Use in-memory SQLite.
  2. Use DatabaseTransactions instead of DatabaseRefresh

Would like to be as close to production-like as possible.

Aucun commentaire:

Enregistrer un commentaire