/
SelfUpdateCommandTest.php
120 lines (99 loc) · 3.31 KB
/
SelfUpdateCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Para\Tests\Unit\Command;
use Para\Command\SelfUpdateCommand;
use Para\Factory\ProcessFactoryInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Process\Process;
/**
* Class SelfUpdateCommandTest
*
* @package Para\Tests\Unit\Command
*/
class SelfUpdateCommandTest extends TestCase
{
/**
* The application.
*
* @var \Symfony\Component\Console\Application
*/
private $application;
/**
* The logger mock object.
*
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* The process factory mock object.
*
* @var \Para\Factory\ProcessFactoryInterface
*/
private $processFactory;
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->logger = $this->prophesize(LoggerInterface::class);
$this->processFactory = $this->prophesize(ProcessFactoryInterface::class);
$this->application = new Application();
$this->application->add(new SelfUpdateCommand(
$this->logger->reveal(),
$this->application,
$this->processFactory->reveal(),
'path/to/tools'
));
}
/**
* Tests that the execute() method returns the output of the successful update process.
*/
public function testTheExecuteMethodReturnsTheOutputOfTheSuccessfulUpdateProcess()
{
$command = $this->application->find('self-update');
$parameters = [
'command' => $command->getName(),
];
$process = $this->prophesize(Process::class);
$process->run()->shouldBeCalled();
$process->getOutput()->willReturn('foo');
$process->getErrorOutput()->willReturn('');
$this->processFactory
->getProcess('./update.sh stable', Argument::type('string'))
->willReturn($process->reveal());
$commandTester = new CommandTester($command);
$commandTester->execute($parameters);
$output = $commandTester->getDisplay();
$this->processFactory
->getProcess(Argument::any(), Argument::any())
->shouldHaveBeenCalled();
$this->assertContains('foo', $output);
}
/**
* Tests that the execute() method returns the error output of the failed update process.
*/
public function testTheExecuteMethodReturnsTheErrorOutputOfTheFailedUpdateProcess()
{
$command = $this->application->find('self-update');
$parameters = [
'command' => $command->getName(),
];
$process = $this->prophesize(Process::class);
$process->run()->shouldBeCalled();
$process->getOutput()->willReturn('foo');
$process->getErrorOutput()->willReturn('bar');
$this->processFactory
->getProcess('./update.sh stable', Argument::type('string'))
->willReturn($process->reveal());
$commandTester = new CommandTester($command);
$commandTester->execute($parameters);
$output = $commandTester->getDisplay();
$this->processFactory
->getProcess(Argument::any(), Argument::any())
->shouldHaveBeenCalled();
$this->assertContains('bar', $output);
}
}