Completed
Push — master ( 4b5b01...595097 )
by Tomáš
05:12
created

testServiceFactoryMethodDoesNotHaveArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Symplify\DefaultAutowire\Tests\DependencyInjection\Definition;
4
5
use PHPUnit\Framework\TestCase;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Symplify\DefaultAutowire\DependencyInjection\Definition\DefinitionAnalyzer;
10
use Symplify\DefaultAutowire\DependencyInjection\Definition\DefinitionValidator;
11
use Symplify\DefaultAutowire\Tests\DependencyInjection\Definition\DefinitionAnalyzerSource\
12
    MissingArgumentsTypehintsFactory;
13
use Symplify\DefaultAutowire\Tests\DependencyInjection\Definition\DefinitionAnalyzerSource\
14
    NotMissingArgumentsTypehintsFactory;
15
use Symplify\DefaultAutowire\Tests\DependencyInjection\Definition\DefinitionAnalyzerSource\EmptyConstructor;
16
use Symplify\DefaultAutowire\Tests\DependencyInjection\Definition\DefinitionAnalyzerSource\EmptyConstructorFactory;
17
use Symplify\DefaultAutowire\Tests\DependencyInjection\Definition\DefinitionAnalyzerSource\MissingArgumentsTypehints;
18
use Symplify\DefaultAutowire\Tests\DependencyInjection\Definition\DefinitionAnalyzerSource\NotMissingArgumentsTypehints;
19
20
final class DefinitionAnalyzerForFactoryTest extends TestCase
21
{
22
    /**
23
     * @var DefinitionAnalyzer
24
     */
25
    private $definitionAnalyzer;
26
27
    protected function setUp()
28
    {
29
        $this->definitionAnalyzer = new DefinitionAnalyzer(new DefinitionValidator());
30
    }
31
32 View Code Duplication
    public function testServiceFactoryMethodDoesNotHaveArguments()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $containerBuilder = new ContainerBuilder();
35
        $containerBuilder->addDefinitions([
36
            'factory' => new Definition(EmptyConstructorFactory::class),
37
        ]);
38
39
        $definition = new Definition(EmptyConstructor::class);
40
        $definition->setFactory([
41
            new Reference('factory'),
42
            'create',
43
        ]);
44
45
        $this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition));
46
    }
47
48
    public function testFactoryMethodDoesNotHaveArguments()
49
    {
50
        $definition = new Definition(EmptyConstructor::class);
51
        $definition->setFactory([
52
            EmptyConstructorFactory::class,
53
            'create',
54
        ]);
55
56
        $this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired(new ContainerBuilder(), $definition));
57
    }
58
59 View Code Duplication
    public function testServiceFactoryBuiltClassHaveMissingArgumentsTypehints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $containerBuilder = new ContainerBuilder();
62
        $containerBuilder->addDefinitions([
63
            'factory' => new Definition(MissingArgumentsTypehintsFactory::class),
64
        ]);
65
66
        $definition = new Definition(MissingArgumentsTypehints::class);
67
        $definition->setFactory([
68
            new Reference('factory'),
69
            'create',
70
        ]);
71
72
        $definition->setArguments(['@someService']);
73
74
        $this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition));
75
    }
76
77 View Code Duplication
    public function testFactoryBuiltClassHaveMissingArgumentsTypehints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $definition = new Definition(MissingArgumentsTypehints::class);
80
        $definition->setFactory([
81
            MissingArgumentsTypehintsFactory::class,
82
            'create',
83
        ]);
84
85
        $definition->setArguments(['@someService']);
86
87
        $this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired(new ContainerBuilder(), $definition));
88
    }
89
90 View Code Duplication
    public function testServiceFactoryBuiltClassHaveNotMissingArgumentsTypehints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $containerBuilder = new ContainerBuilder();
93
        $containerBuilder->addDefinitions([
94
            'factory' => new Definition(NotMissingArgumentsTypehintsFactory::class),
95
        ]);
96
97
        $definition = new Definition(NotMissingArgumentsTypehints::class);
98
        $definition->setFactory([
99
            new Reference('factory'),
100
            'create',
101
        ]);
102
103
        $definition->setArguments(['@someService']);
104
105
        $this->assertTrue($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition));
106
    }
107
108 View Code Duplication
    public function testFactoryBuiltClassHaveNotMissingArgumentsTypehints()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
    {
110
        $definition = new Definition(NotMissingArgumentsTypehints::class);
111
        $definition->setFactory([
112
            NotMissingArgumentsTypehintsFactory::class,
113
            'create',
114
        ]);
115
116
        $definition->setArguments(['@someService']);
117
118
        $this->assertTrue($this->definitionAnalyzer->shouldDefinitionBeAutowired(new ContainerBuilder(), $definition));
119
    }
120
}
121