Completed
Push — feature/no-more-lost-in-redepl... ( b5e1b8...088e5a )
by Lucas
16:03
created

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