Tsekka
1 month ago
200
3
Testing

Laravel testing - can't connect to DB on Unit test (but works perfectly in Feature test)?

Posted 1 month ago by Tsekka

I have defined database on phpunit.xml.

On my test I need to connect to database (Schema::getColumnListing('tablename');).

Everything works perfectly if test is in Feature folder, but in Unit folder exactly the same test returns this error:


  at C:\xampp\htdocs\dev\whatever\vendor\laravel\framework\src\Illuminate\Support\Facades\Schema.php:41
     37▕      * @return \Illuminate\Database\Schema\Builder
     38▕      */
     39▕     protected static function getFacadeAccessor()
     40▕     {
  ➜  41▕         return static::$app['db']->connection()->getSchemaBuilder();
     42▕     }
     43▕ }
     44▕

  1   C:\xampp\htdocs\dev\bookus\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:166
      Illuminate\Support\Facades\Schema::getFacadeAccessor()

  2   C:\xampp\htdocs\dev\bookus\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:255
      Illuminate\Support\Facades\Facade::getFacadeRoot()

Should I define database connection for Unit test separately somewhere else (where?) or is there anything else I'm missing here?

Thanks.

Please sign in or create an account to participate in this conversation.