Completed
Push — master ( f096ba...8214a5 )
by Gerrit
03:01
created

BarTest::shouldApplyDecoratorTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 9.0254
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\DependencyInjection\Compiler\DecoratorTemplateCompilerPass;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Reference;
18
use InvalidArgumentException;
19
20
final class BarTest extends TestCase
21
{
22
23
    /**
24
     * @test
25
     */
26
    public function shouldApplyDecoratorTemplate()
27
    {
28
        /** @var Reference $oldReference */
29
        $oldReference = $this->createMock(Reference::class);
30
        $oldReference->method('__toString')->willReturn('some-string-representation');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Symfony\Component...ncyInjection\Reference>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
        $oldReference->method('getInvalidBehavior')->willReturn(1);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Symfony\Component...ncyInjection\Reference>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33
        /** @var Definition $decoratorDefinition */
34
        $decoratorDefinition = $this->createMock(Definition::class);
35
        $decoratorDefinition->method('getTags')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean addMethodCall()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
            'some.tag.name' => 'foo'
37
        ]);
38
        $decoratorDefinition->expects($this->once())->method('setTags')->with([
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...cyInjection\Definition>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        ]);
40
        $decoratorDefinition->method('getArguments')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean addMethodCall()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
            'foo',
42
            ['bar', 123, '%some_param%'],
43
            ['abc' => ['def' => $oldReference]],
44
            new Reference('some-decorator-service-id.inner', 1)
45
        ]);
46
        $decoratorDefinition->expects($this->once())->method('setArguments')->with([
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...cyInjection\Definition>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            'foo',
48
            ['bar', 123, 'some-resolved'],
49
            ['abc' => ['def' => new Reference('some-string-representation', 1)]],
50
            new Reference('some-decorated-service-id.some.tag.name.some-decorator-service-id.inner', 1)
51
        ]);
52
        $decoratorDefinition->expects($this->once())->method('setDecoratedService')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...cyInjection\Definition>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            $this->equalTo('some-decorated-service-id')
54
        );
55
56
        /** @var ContainerBuilder $container */
57
        $container = $this->createMock(ContainerBuilder::class);
58
        $container->expects($this->once())->method('findTaggedServiceIds')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
            $this->equalTo("some.tag.name")
60
        )->willReturn([
61
            'some-decorator-service-id' => [
62
                ['decorates' => 'some-decorated-service-id', 'some_param' => 'some-resolved']
63
            ]
64
        ]);
65
        $container->expects($this->once())->method('getDefinition')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
            $this->equalTo('some-decorator-service-id')
67
        )->willReturn($decoratorDefinition);
68
        $container->expects($this->once())->method('setDefinition')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
            $this->equalTo("some-decorated-service-id.some.tag.name.some-decorator-service-id"),
70
            $this->equalTo($decoratorDefinition)
71
        );
72
        $container->expects($this->once())->method('removeDefinition')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
            $this->equalTo("some-decorator-service-id")
74
        );
75
76
        $compilerPass = new DecoratorTemplateCompilerPass("some.tag.name");
77
        $compilerPass->process($container);
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function shouldExpectDecoratesKeyInTags()
84
    {
85
        $this->expectException(InvalidArgumentException::class);
86
87
        /** @var ContainerBuilder $container */
88
        $container = $this->createMock(ContainerBuilder::class);
89
        $container->expects($this->once())->method('findTaggedServiceIds')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
            $this->equalTo("some.tag.name")
91
        )->willReturn([
92
            'some-decorator-service-id' => [
93
                ['some_param' => 'some-resolved']
94
            ]
95
        ]);
96
97
        $compilerPass = new DecoratorTemplateCompilerPass("some.tag.name");
98
        $compilerPass->process($container);
99
    }
100
101
    /**
102
     * @test
103
     */
104
    public function shouldExpectTypeTagInDecoratorTags()
105
    {
106
        $this->expectException(InvalidArgumentException::class);
107
108
        /** @var Definition $decoratorDefinition */
109
        $decoratorDefinition = $this->createMock(Definition::class);
110
        $decoratorDefinition->method('getTags')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean addMethodCall()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
111
        ]);
112
113
        /** @var ContainerBuilder $container */
114
        $container = $this->createMock(ContainerBuilder::class);
115
        $container->expects($this->once())->method('findTaggedServiceIds')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
            $this->equalTo("some.tag.name")
117
        )->willReturn([
118
            'some-decorator-service-id' => [
119
                ['decorates' => 'some-decorated-service-id', 'some_param' => 'some-resolved']
120
            ]
121
        ]);
122
        $container->expects($this->once())->method('getDefinition')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Symfony\Component...ction\ContainerBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
            $this->equalTo('some-decorator-service-id')
124
        )->willReturn($decoratorDefinition);
125
126
        $compilerPass = new DecoratorTemplateCompilerPass("some.tag.name");
127
        $compilerPass->process($container);
128
    }
129
130
}
131