1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ozean12\WebTranslateItBundle\Tests\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Ozean12\WebTranslateItBundle\Command\TranslationsPullCommand; |
7
|
|
|
use Ozean12\WebTranslateItBundle\DTO\ProjectDTO; |
8
|
|
|
use Ozean12\WebTranslateItBundle\DTO\ProjectFileDTO; |
9
|
|
|
use Ozean12\WebTranslateItBundle\DTO\PullProjectResponseDTO; |
10
|
|
|
use Ozean12\WebTranslateItBundle\Service\TranslationRepositoryInterface; |
11
|
|
|
use Ozean12\WebTranslateItBundle\Service\WebTranslateItFileService; |
12
|
|
|
use Ozean12\WebTranslateItBundle\Service\WebTranslateItRepository; |
13
|
|
|
use Symfony\Component\Console\Application; |
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class TranslationsPullCommandTest |
20
|
|
|
*/ |
21
|
|
|
class TranslationsPullCommandTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
private $projectName = "Yuri Gagarin"; |
24
|
|
|
private $projectFileName = "Ole Einar Bjoerndalen"; |
25
|
|
|
private $translationDirectory = "in/a/galaxy/far/far/away"; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var WebTranslateItRepository|\PHPUnit_Framework_MockObject_MockObject |
29
|
|
|
*/ |
30
|
|
|
private $repositoryMock; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var WebTranslateItFileService|\PHPUnit_Framework_MockObject_MockObject |
34
|
|
|
*/ |
35
|
|
|
private $fileServiceMock; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Application |
39
|
|
|
*/ |
40
|
|
|
private $application; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Command |
44
|
|
|
*/ |
45
|
|
|
private $command; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var CommandTester |
49
|
|
|
*/ |
50
|
|
|
private $commandTester; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set up |
54
|
|
|
*/ |
55
|
|
|
public function setUp() |
56
|
|
|
{ |
57
|
|
|
// Mocking of the repository |
58
|
|
|
$this->repositoryMock = $this->getMockBuilder(TranslationRepositoryInterface::class) |
59
|
|
|
->disableOriginalConstructor() |
60
|
|
|
->setMethods(['pullProject', 'pullFile']) |
61
|
|
|
->getMock(); |
62
|
|
|
|
63
|
|
|
$projectResponseDTO = new PullProjectResponseDTO(); |
64
|
|
|
$projectDTO = (new ProjectDTO()) |
65
|
|
|
->setName($this->projectName) |
66
|
|
|
->setProjectFiles( |
67
|
|
|
new ArrayCollection( |
68
|
|
|
[ |
69
|
|
|
(new ProjectFileDTO())->setName($this->projectFileName), |
70
|
|
|
] |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$projectResponseDTO->setProject( |
75
|
|
|
$projectDTO |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->repositoryMock->expects($this->any())->method('pullProject')->willReturn( |
79
|
|
|
$projectResponseDTO |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->repositoryMock->expects($this->any())->method('pullFile')->willReturn($this->projectFileName); |
83
|
|
|
|
84
|
|
|
// Mocking of the file service |
85
|
|
|
|
86
|
|
|
$this->fileServiceMock = $this->getMockBuilder(WebTranslateItFileService::class) |
87
|
|
|
->setConstructorArgs([$this->repositoryMock]) |
88
|
|
|
->setMethods(['prepare', 'update', 'shouldBeUpdated']) |
89
|
|
|
->getMock(); |
90
|
|
|
|
91
|
|
|
$this->fileServiceMock->expects($this->any())->method('shouldBeUpdated')->willReturn(true); |
92
|
|
|
|
93
|
|
|
$command = new TranslationsPullCommand( |
94
|
|
|
$this->repositoryMock, |
95
|
|
|
$this->fileServiceMock, |
96
|
|
|
$this->translationDirectory |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->application = new Application(); |
100
|
|
|
$this->application->add($command); |
101
|
|
|
|
102
|
|
|
$this->command = $this->application->find('ozean12:webtranslateit:pull'); |
103
|
|
|
$this->commandTester = new CommandTester($this->command); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Proves that the execution of the command is valid |
108
|
|
|
*/ |
109
|
|
|
public function testExecuteValid() |
110
|
|
|
{ |
111
|
|
|
$this->commandTester->execute( |
112
|
|
|
[ |
113
|
|
|
'command' => $this->command->getName(), |
114
|
|
|
], |
115
|
|
|
[ |
116
|
|
|
'verbosity' => OutputInterface::VERBOSITY_VERBOSE, |
117
|
|
|
] |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
$this->assertRegExp('/Pulling translations for/', $this->commandTester->getDisplay()); |
121
|
|
|
$this->assertRegExp('/Translations updated/', $this->commandTester->getDisplay()); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|