I'm just starting a new laravel 10 project and wanted to give Pest a go. However my initial attempts are not going well.
I have a really simple test to play around:
<?php
namespace Tests\Unit;
use App\Http\Controllers\AvatarController;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
test('create a user', function(){
$user = User::factory()->create();
expect($user->avatar())->toBeNull();
});
this fails with:
Call to a member function connection() on null
at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1820
1816▕ * @return \Illuminate\Database\Connection
1817▕ */
1818▕ public static function resolveConnection($connection = null)
1819▕ {
➜ 1820▕ return static::$resolver->connection($connection);
1821▕ }
1822▕
1823▕ /**
1824▕ * Get the connection resolver instance.
+13 vendor frames
14 tests/Unit/AvatarTest.php:13
Tests: 1 failed (0 assertions)
Duration: 0.28s
in Model.php if I dd(static::$resolver) it is null
The default ProfileTest.php runs fine with the same factory call
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ProfileTest extends TestCase
{
use RefreshDatabase;
public function test_profile_page_is_displayed(): void
{
$user = User::factory()->create();
//
}
}
Any help would be brilliant!