简体   繁体   English

测试Symfony 4的可重用捆绑包

[英]Test reusable bundle for symfony 4

I try to create a reusable bundle with one service who implement an interface and one annotation. 我尝试使用一个实现接口和一个批注的服务来创建可重用的捆绑包。 In DependencyInjection I create Configuration class with the method getConfigTreeBuilder 在DependencyInjection中,我使用getConfigTreeBuilder方法创建Configuration类。

public function getConfigTreeBuilder()
{
    $treeBuilder = new TreeBuilder();
    $treeBuilder->root('sow_binding', 'array');
    return $treeBuilder;
}

and Extension class who load services.yaml in config directory. 和Extension类在配置目录中加载services.yaml。

public function load(array $configs, ContainerBuilder $container)
{
    $loader = new YamlFileLoader(
        $container,
        new FileLocator(__DIR__.'/../Resources/config')
    );
    $loader->load('services.yaml');
}

I created one test who create a fake class who use my annotation and my service but I get this message when I execute it : 我创建了一个测试,该测试创建了一个使用我的注释和服务的伪造类,但是执行该消息时会收到以下消息:

Error : Class 'SOW\BindingBundle\Service\BindingService' not found

In my test I instantiated my service like this (with right import) : 在我的测试中,我以如下方式实例化了我的服务(带有正确的导入):

$bindingService = new BindingService($reader, 'SOW\Annotation\Binding');

Here my services.yaml file : 这是我的services.yaml文件:

parameters:
    binding.annotation.class: SOW\Annotation\Binding

services:
    SOW\BindingBundle\Service\BindingService:
        alias: sow_binding.binder
        public: true
        arguments:
            - "@annotations.reader"
            - "%app.binding.annotation.class%"

Why my test can't find my service ? 为什么我的考试找不到我的服务?

Remove the app from binding. 从绑定中删除该应用。 annotation. 注解。 class as its not a valid reference. 类为无效参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM