Hello I write test and want to get data from DB in it, so I do next
Company.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
protected $table = 'companies';
}
MyTest.php
<?php
use App\Models\Company;
class MyTest extends TestCase {
public function testFileUploadAction()
{
$company = Company::find(1);
}
}
but have error
Fatal error: Call to a member function connection() on a non-object in /myproject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 3146
So how I can get data From DB in test?
Update: all my tests work fine issue only in get data from DB in test.
Model work fine.
**Update I found solution error was because application wasn't booted so I add
$app = require __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
and all work fine