1) App\Tests\Controller\Admin\Api\Promotion\PromotionDeleteControllerTest::test_deleting_promotion
LogicException: The first argument of "Symfony\Bundle\FrameworkBundle\KernelBrowser::loginUser" must be instance of "Symfony\Component\Security\Core\User\UserInterface", "Zenstruck\Foundry\Proxy" provided.
I am writing functional test with phpunit library. I want to create admin object for testing with AdminFactory (extends Foundry ModelFactory) and then authenticate my API request using given object with built in Symfony method
$this->client->loginUser($admin, 'admin');
How can I make it work?
CodePudding user response:
Okay, I've found a solution myself. You have to do something like this:
AdminFactory::new()
->create([
'email' => '[email protected]',
'active' => true,
'roles' => ['ROLE_SUPER_ADMIN'],
])
;
/** @var AdminRepository $adminRepository */
$adminRepository = static::getContainer()->get(AdminRepository::class);
$admin = $adminRepository->findOneBy(['email' => '[email protected]']);
This should return Entity instead of Foundry Proxy