gpt4 book ai didi

Symfony4/Behat 注入(inject)功能不工作 "you have requested a non-existen service"

转载 作者:行者123 更新时间:2023-12-04 04:00:48 27 4
gpt4 key购买 nike

对于测试用例,我需要能够使用现有服务,但该服务不能在我的 behat 上下文中使用:

上下文:

/**
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".

有人可以提供帮助或知道为什么会显示此错误消息吗?该服务确实在使用的 Controller 中工作。所以服务本身应该没有错误,只是将此服务注入(inject) behat。

最佳答案

您可以按照此处的说明注入(inject)容器并访问私有(private)服务:https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing

关于Symfony4/Behat 注入(inject)功能不工作 "you have requested a non-existen service",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63074583/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com