1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace BaleenTest\Cli\CommandBus\Timeline; |
21
|
|
|
|
22
|
|
|
use Baleen\Cli\CommandBus\Timeline\ExecuteMessage; |
23
|
|
|
use Baleen\Cli\CommandBus\Timeline\ExecuteHandler; |
24
|
|
|
use Baleen\Migrations\Migration\Options; |
25
|
|
|
use Baleen\Migrations\Timeline; |
26
|
|
|
use Baleen\Migrations\Version; |
27
|
|
|
use BaleenTest\Cli\CommandBus\HandlerTestCase; |
28
|
|
|
use Mockery as m; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class ExecuteHandlerTest |
32
|
|
|
* @author Gabriel Somoza <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class ExecuteHandlerTest extends HandlerTestCase |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* setUp |
38
|
|
|
*/ |
39
|
|
|
public function setUp() |
40
|
|
|
{ |
41
|
|
|
$this->instance = m::mock(ExecuteHandler::class) |
42
|
|
|
->shouldAllowMockingProtectedMethods() |
43
|
|
|
->makePartial(); |
44
|
|
|
$this->command = m::mock(ExecuteMessage::class)->makePartial(); |
45
|
|
|
parent::setUp(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* testHandle |
50
|
|
|
* @param $isInteractive |
51
|
|
|
* @param $isUp |
52
|
|
|
* @param $isDryRun |
53
|
|
|
* @param $askResult |
54
|
|
|
* @dataProvider executeProvider |
55
|
|
|
*/ |
56
|
|
|
public function testHandle($isInteractive, $isUp, $isDryRun, $askResult, $executeResult) |
57
|
|
|
{ |
58
|
|
|
/** @var m\Mock|Timeline $timeline */ |
59
|
|
|
$timeline = m::mock(Timeline::class); |
60
|
|
|
$this->input->shouldReceive('isInteractive')->once()->andReturn($isInteractive); |
61
|
|
|
$this->input->shouldReceive('getArgument')->with(ExecuteMessage::ARG_VERSION)->once()->andReturn('123'); |
62
|
|
|
$this->input->shouldReceive('getArgument')->with(ExecuteMessage::ARG_DIRECTION)->once()->andReturn(!$isUp); |
63
|
|
|
$this->input->shouldReceive('getOption')->with(ExecuteMessage::OPT_DRY_RUN)->once()->andReturn($isDryRun); |
64
|
|
|
|
65
|
|
|
if ($isInteractive) { |
66
|
|
|
$this->output->shouldReceive('writeln')->once()->with('/WARNING/'); |
67
|
|
|
$this->assertQuestionAsked($askResult, m::type('Symfony\Component\Console\Question\ConfirmationQuestion')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (!$isInteractive || $askResult) { |
71
|
|
|
$timeline->shouldReceive('runSingle')->with( |
72
|
|
|
m::on(function ($version) { |
73
|
|
|
return (string) $version === '123'; |
74
|
|
|
}), |
75
|
|
|
m::on(function (Options $options) use ($isUp, $isDryRun) { |
76
|
|
|
return $options->isDryRun() === $isDryRun |
77
|
|
|
&& $options->isDirectionUp() === $isUp; |
78
|
|
|
}) |
79
|
|
|
)->once()->andReturn($executeResult); |
80
|
|
|
if ($executeResult && !$isDryRun) { |
81
|
|
|
$this->command->shouldReceive('getStorage->update')->with($executeResult)->once(); |
82
|
|
|
} |
83
|
|
|
$this->output->shouldReceive('writeln')->once()->with('/successfully/'); |
84
|
|
|
$this->command->shouldReceive('getTimeline')->once()->andReturn($timeline); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->handle(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function executeProvider() |
94
|
|
|
{ |
95
|
|
|
return $this->combinations([ |
96
|
|
|
[true, false], // isInteractive |
97
|
|
|
[true, false], // isUp |
98
|
|
|
[true, false], // isDryRun |
99
|
|
|
[true, false], // askResult |
100
|
|
|
[new Version(1), false, null] // executeResult |
101
|
|
|
]); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|