Conditions | 1 |
Paths | 1 |
Total Lines | 79 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 |