php - 在 Symfony 5.3 phpunit 测试期间,“security.user_password_hasher”的定义没有类?
问题描述
这个问题在某种程度上与:如何在 Symfony 5.3 phpunit 测试中访问私有服务?. 我通过以下方式设置环境services_test.yaml
:
services:
security.user_password_hasher:
public: true
当我尝试检索时,出现security.user_password_hasher
异常:
$encoded = static::getContainer()->get('security.user_password_hasher')->hashPassword($user, $password);
Symfony\Component\DependencyInjection\Exception\RuntimeException:“security.user_password_hasher”的定义没有类。如果您打算在运行时动态注入此服务,请将其标记为 synthet=true。如果这是一个仅由子定义使用的抽象定义,请添加abstract=true,否则指定一个类以消除此错误。
为什么我得到这个异常?在我检索的同一个测试套件EntityManagerInterface::class
中,一切都很好。
当我通过将其注入控制器来访问 env UserPasswordHasherInterface
(它是 security.user_password_hasher 的别名)时,不会引发错误。为什么将其设置更改为崩溃测试?就是这个服务比较特殊,在环境中需要特别注意?或者可能是因为env 更改了一些默认设置?dev
public function homepage(UserPasswordHasherInterface $hash)
public: true
test
test
我是 Symfony 的新手。我的猜测是容器做了一些隐藏的魔法。有人能透露秘密吗?什么意思:[注意] 在编译容器时,“security.user_password_hasher”服务或别名已被删除或内联?
解决方案
推荐阅读
- python - 如何使用 pandas 为每个用户的选定列填充 NA 的最小值
- php - 如何将数组的多个复选框值插入数据库
- servicestack - PocoDynamo(提供的关键元素与架构不匹配)
- java - Sbt RootProject 或 ProjectRef 不下载 github 项目内容
- android - 如何使用 Glide 检测 gif 的完成情况?
- flutter - 从已知 documentID 返回单个 Firestore 字段值
- asp.net-mvc - .net核心如何在autofac中注册ihubcontext
- sql - 如何一起使用 COUNT 和 MAX 但分组?
- vuetify.js - Vuetify 阻塞 UI 几秒钟
- javascript - 如何给我的 JSON 字典一个主键,而不将它实现到我的循环中?