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.
我正在用 phpunit 庫撰寫功能測驗。我想創建管理物件以使用 AdminFactory(擴展 Foundry ModelFactory)進行測驗,然后使用內置 Symfony 方法的給定物件驗證我的 API 請求
$this->client->loginUser($admin, 'admin');
我怎樣才能讓它作業?
uj5u.com熱心網友回復:
好的,我自己找到了解決方案。你必須做這樣的事情:
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]']);
這應該回傳 Entity 而不是 Foundry Proxy
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/476229.html
