| 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 | 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 |