model = $objectManager->get(Issuer::class); $this->customerRepo = $objectManager->get(CustomerRepositoryInterface::class); $this->userModel = $objectManager->create(UserModel::class); $this->paramsFactory = $objectManager->get(UserTokenParametersFactory::class); } /** * Verify that a token can be issued for a customer. * * @return void * @throws \Throwable * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testIssueForCustomer(): void { $customer = $this->customerRepo->get('customer@example.com'); /** @var UserTokenParameters $params */ $params = $this->paramsFactory->create(); $token = $this->model->create( new CustomUserContext((int) $customer->getId(), UserContextInterface::USER_TYPE_CUSTOMER), $params ); $this->assertNotEmpty($token); } /** * Verify that a token can be issued for an admin user. * * @return void * @throws \Throwable * @magentoDataFixture Magento/User/_files/user_with_role.php */ public function testIssueForAdmin(): void { $admin = $this->userModel->loadByUsername('adminUser'); /** @var UserTokenParameters $params */ $params = $this->paramsFactory->create(); $token = $this->model->create( new CustomUserContext((int) $admin->getId(), UserContextInterface::USER_TYPE_ADMIN), $params ); $this->assertNotEmpty($token); } }