Completed
Pull Request — develop (#422)
by Lucas
06:22
created

testLoadCreateCommand()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 79
rs 8.8701
cc 1
eloc 60
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
 * functional tests for creating translation resource files
4
 */
5
6
namespace Graviton\I18nBundle\Tests\Command;
7
8
use Symfony\Component\Console\Tester\CommandTester;
9
use Graviton\GeneratorBundle\Command\GenerateBundleCommand;
10
11
/**
12
 * functional tests for graviton:generate:bundle
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 *
18
 * @todo fix that updateKernel is not getting tested
19
 */
20
class CreateTranslationResourcesCommandTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * test graviton:i118n:create:resources command
24
     *
25
     * @return void
26
     */
27
    public function testLoadCreateCommand()
28
    {
29
        $languageMock = $this->getMockBuilder('\Graviton\I18nBundle\Repository\LanguageRepository')
30
            ->disableOriginalConstructor()
31
            ->getMock();
32
33
        $enMock = $this->getMock('\Graviton\I18nBundle\Document\Language');
34
        $enMock->expects($this->any())->method('getId')->willReturn('en');
35
36
        $deMock = $this->getMock('\Graviton\I18nBundle\Document\Language');
37
        $deMock->expects($this->any())->method('getId')->willReturn('de');
38
39
        $languageMock->expects($this->once())
40
            ->method('findAll')
41
            ->willReturn([$enMock, $deMock]);
42
43
        $translatableMock = $this->getMockBuilder('\Graviton\I18nBundle\Repository\TranslatableRepository')
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
47
        $builderMock = $this->getMockbuilder('\Doctrine\ODM\MongoDB\Query\Builder')
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
51
        $builderMock
52
            ->expects($this->once())
53
            ->method('distinct')
54
            ->with('domain')
55
            ->willReturn($builderMock);
56
57
        $builderMock
58
            ->expects($this->once())
59
            ->method('select')
60
            ->with('domain')
61
            ->willReturn($builderMock);
62
63
        $queryMock = $this->getMockBuilder('\Doctrine\ODM\MongoDB\Query\Query')
64
            ->disableOriginalConstructor()
65
            ->getMock();
66
67
        $builderMock
68
            ->expects($this->once())
69
            ->method('getQuery')
70
            ->willReturn($queryMock);
71
72
        $queryMock
73
            ->expects($this->once())
74
            ->method('execute')
75
            ->willReturn($queryMock);
76
        $queryMock
77
            ->expects($this->once())
78
            ->method('toArray')
79
            ->willReturn(['core', 'i18n']);
80
81
        $translatableMock
82
            ->expects($this->once())
83
            ->method('createQueryBuilder')
84
            ->willReturn($builderMock);
85
86
        $fsMock = $this->getMock('\Symfony\Component\Filesystem\Filesystem');
87
88
        $fsMock->expects($this->exactly(4))
89
            ->method('touch');
90
91
        $command = new CommandTester(
92
            new \Graviton\I18nBundle\Command\CreateTranslationResourcesCommand(
93
                $languageMock,
94
                $translatableMock,
95
                $fsMock
96
            )
97
        );
98
        $command->execute(array());
99
100
        $this->assertContains('Creating translation resource stubs', $command->getDisplay());
101
        $this->assertContains('Generated file core.en.odm', $command->getDisplay());
102
        $this->assertContains('Generated file core.de.odm', $command->getDisplay());
103
        $this->assertContains('Generated file i18n.en.odm', $command->getDisplay());
104
        $this->assertContains('Generated file i18n.de.odm', $command->getDisplay());
105
    }
106
}
107