当初以下のようなコードを書いていたのだが、
namespace Tests\Unit\Repositories;
use PHPUnit\Framework\TestCase;
use App\Models\User;
use App\Constants;
use App\Repositories\PgSql\UserRepository;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
class UserRepositoryTest extends TestCase
{
use WithFaker, RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
}
// expected 1 user is found, not others.
public function testFindUserByAuthInfo()
{
$repo = new UserRepository();
// findable
$user = factory(User::class)->create([
'id' => $this->faker->uuid,
'password' => password_hash($this->faker->password(), PASSWORD_BCRYPT),
'account_id' => 1,
'email' => $this->faker->email,
]);
実行すると
1) Tests\Unit\Repositories\UserRepositoryTest::testFindUserByAuthInfo
Trying to get property 'uuid' of non-object
と$this->fakerでFakerがインスタンス化できていない模様
散々調べた挙げ句、結局
use PHPUnit\Framework\TestCase;
を
use Tests\TestCase;
にしたら直ったというお話。