lundi 8 février 2021

Is Laravel 8 Testing with a database broken out of the box

I have a new Laravel 8 install, running on docker with sail. Everything seems to run fine, but tests that use any configuration seem to be broken. For example a simple test that pulls a user out of the database fails.

I am using the default phpunit.xml, and I added a .env.testing, which is just a copy of .env

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

Added a quick test to the unit ExampleTest.php

/**
 * A basic test example.
 *
 * @return void
 */
public function testBasicTest()
{
    $user = User::find(1);
    $this->assertInstanceOf(User::class, $user);
}

Run sail php artisan test Tests: 1 failed, 16 passed Time: 2.70s

• Tests\Unit\ExampleTest > basic test
   Error 

  Call to a member function connection() on null

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1493
    1489▕      * @return \Illuminate\Database\Connection
    1490▕      */
    1491▕     public static function resolveConnection($connection = null)
    1492▕     {
  ➜ 1493▕         return static::$resolver->connection($connection);
    1494▕     }
    1495▕ 
    1496▕     /**
    1497▕      * Get the connection resolver instance.

I have a number of laravel apps that run these exact same test in previous versions of Laravel. What am I missing?

Thanks,

Aucun commentaire:

Enregistrer un commentaire