【发布时间】:2020-11-14 09:06:21
【问题描述】:
对于测试用例,我需要能够使用现有服务,但该服务不能在我的行为上下文中使用:
上下文:
/**
class CustomContext extends MinkContext implements KernelAwareContext {
# ...
* @param EntityManagerInterface $em
* @param HttpCallResultPool $httpCallResultPool
* @param SessionInterface $session
* @param CustomService $customService
* @param string $evaluationMode
*/
public function __construct(
EntityManagerInterface $em,
HttpCallResultPool $httpCallResultPool,
SessionInterface $session,
CustomService $customService,
string $evaluationMode = 'javascript'
) {
$this->em = $em;
$this->client = new Client();
$this->inspector = new JsonInspector($evaluationMode);
$this->httpCallResultPool = $httpCallResultPool;
$this->session = $session;
$this->customService= $customService;
}
behat.yaml:
# ...
Behat\Symfony2Extension:
kernel:
bootstrap: 'config/bootstrap.php'
path: 'src/Kernel.php'
class: 'App\Kernel'
env: dev
debug: false
# ...
suites:
default:
contexts:
- App\CustomContext:
em: '@doctrine.orm.default_entity_manager'
session: '@session'
customService: '@App\Service\CustomService'
Fehlermeldung:
In Container.php line 289:
You have requested a non-existent service "App\Service\CustomService".
有人可以帮忙或知道为什么会显示此错误消息吗? 该服务确实在使用的控制器中工作。所以服务本身应该没有错误,只有注入这个服务。
【问题讨论】:
-
SO 上有一个类似的question,建议查看symfony.com/doc/current/reference/configuration/…
-
谢谢,但已经尝试过了,但没有帮助。我认为这一定不是由 symfony 引起的,而是 bei behats 尝试注入服务