Completed
Push — feature/EVO-5751-text-index-mo... ( 0ab3ac...8fecb1 )
by
unknown
62:16 queued 57:01
created

ExtRefFieldsCompilerPassTest::testProcess()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 76
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 76
rs 8.9667
cc 1
eloc 61
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
 * ExtRefFieldsCompilerPassTest class file
4
 */
5
6
namespace Graviton\DocumentBundle\Tests\DependencyInjection\CompilerPass;
7
8
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefFieldsCompilerPass;
9
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\DocumentMap;
10
use Symfony\Component\Finder\Finder;
11
12
/**
13
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link    http://swisscom.ch
16
 */
17
class ExtRefFieldsCompilerPassTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @return void
21
     */
22
    public function testProcess()
23
    {
24
        $serviceDouble = $this
25
            ->getMockBuilder('Symfony\\Component\\DependencyInjection\\Definition')
26
            ->disableOriginalConstructor()
27
            ->setMethods(['getTag'])
28
            ->getMock();
29
        $serviceDouble
30
            ->expects($this->once())
31
            ->method('getTag')
32
            ->with('graviton.rest')
33
            ->willReturn([]);
34
35
        $containerDouble = $this
36
            ->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerBuilder')
37
            ->disableOriginalConstructor()
38
            ->getMock();
39
        $containerDouble
40
            ->expects($this->once())
41
            ->method('findTaggedServiceIds')
42
            ->with('graviton.rest')
43
            ->willReturn(['gravitonTest.document.controller.A' => []]);
44
        $containerDouble
45
            ->expects($this->once())
46
            ->method('getDefinition')
47
            ->with('gravitonTest.document.controller.A')
48
            ->willReturn($serviceDouble);
49
        $containerDouble
50
            ->expects($this->once())
51
            ->method('setParameter')
52
            ->with(
53
                $this->equalTo('graviton.document.extref.fields'),
54
                [
55
                    'gravitontest.document.rest.a.get' => [
56
                        '$exposedRefA',
57
58
                        'achild.$exposedRefB',
59
                        'achild.bchild.$exposedRefC',
60
                        'achild.bchildren.0.$exposedRefC',
61
62
                        'achildren.0.$exposedRefB',
63
                        'achildren.0.bchild.$exposedRefC',
64
                        'achildren.0.bchildren.0.$exposedRefC',
65
                    ],
66
                    'gravitontest.document.rest.a.all' => [
67
                        '$exposedRefA',
68
69
                        'achild.$exposedRefB',
70
                        'achild.bchild.$exposedRefC',
71
                        'achild.bchildren.0.$exposedRefC',
72
73
                        'achildren.0.$exposedRefB',
74
                        'achildren.0.bchild.$exposedRefC',
75
                        'achildren.0.bchildren.0.$exposedRefC',
76
                    ],
77
                ]
78
            );
79
80
        $documentMap = new DocumentMap(
81
            (new Finder())
82
                ->in(__DIR__.'/Resources/doctrine/extref')
83
                ->name('*.mongodb.xml'),
84
            (new Finder())
85
                ->in(__DIR__.'/Resources/serializer/extref')
86
                ->name('*.xml'),
87
            (new Finder())
88
                ->in(__DIR__.'/Resources/validation/extref')
89
                ->name('*.xml'),
90
            (new Finder())
91
                ->in(__DIR__.'/Resources/schema')
92
                ->name('*.json')
93
        );
94
95
        $compilerPass = new ExtRefFieldsCompilerPass($documentMap);
96
        $compilerPass->process($containerDouble);
97
    }
98
}
99