|
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\Config; |
|
21
|
|
|
|
|
22
|
|
|
use Baleen\Cli\CommandBus\Config\InitMessage; |
|
23
|
|
|
use Baleen\Cli\CommandBus\Config\InitHandler; |
|
24
|
|
|
use Baleen\Cli\Config\Config; |
|
25
|
|
|
use Baleen\Cli\Config\ConfigStorage; |
|
26
|
|
|
use BaleenTest\Cli\CommandBus\HandlerTestCase; |
|
27
|
|
|
use Mockery as m; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class InitHandlerTest |
|
31
|
|
|
* @author Gabriel Somoza <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class InitHandlerTest extends HandlerTestCase |
|
34
|
|
|
{ |
|
35
|
|
|
|
|
36
|
|
|
/** @var m\Mock|ConfigStorage */ |
|
37
|
|
|
protected $configStorage; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* setUp |
|
41
|
|
|
*/ |
|
42
|
|
View Code Duplication |
public function setUp() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->instance = m::mock(InitHandler::class)->makePartial(); |
|
45
|
|
|
$this->command = m::mock(InitMessage::class)->makePartial(); |
|
46
|
|
|
$this->configStorage = m::mock(ConfigStorage::class); |
|
47
|
|
|
$this->command->shouldReceive('getConfigStorage')->zeroOrMoreTimes()->andReturn($this->configStorage); |
|
48
|
|
|
parent::setUp(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param $writeResult |
|
53
|
|
|
* @dataProvider executeProvider |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testExecute($writeResult) |
|
56
|
|
|
{ |
|
57
|
|
|
$configFileName = '.baleen.yml'; |
|
58
|
|
|
|
|
59
|
|
|
/** @var m\Mock|Config $config */ |
|
60
|
|
|
$config = m::mock(Config::class); |
|
61
|
|
|
|
|
62
|
|
|
$this->command->setConfig($config); |
|
63
|
|
|
|
|
64
|
|
|
$resultMessage = $writeResult ? 'created at' : 'Could not create'; |
|
65
|
|
|
$this->output->shouldReceive('writeln')->with(m::on(function($message) use ($resultMessage) { |
|
66
|
|
|
return strpos($message, $resultMessage) !== false; |
|
67
|
|
|
}))->once(); |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$config->shouldReceive('getFileName')->once()->andReturn($configFileName); |
|
71
|
|
|
$this->configStorage->shouldReceive('isInitialized')->once()->andReturn(false); |
|
72
|
|
|
$this->configStorage->shouldReceive('write')->once()->andReturn($writeResult); |
|
73
|
|
|
|
|
74
|
|
|
$this->handle(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
public function executeProvider() |
|
81
|
|
|
{ |
|
82
|
|
|
return [ |
|
83
|
|
|
[ true ], |
|
84
|
|
|
[ false ], |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* testExecuteExitsEarlyIfFileExists |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testExecuteExitsEarlyIfFileExists() |
|
92
|
|
|
{ |
|
93
|
|
|
/** @var m\Mock|Config $config */ |
|
94
|
|
|
$config = m::mock(Config::class); |
|
95
|
|
|
$this->command->setConfig($config); |
|
96
|
|
|
$this->command->shouldReceive('getCliCommand->getApplication->getName')->andReturn('Baleen'); |
|
97
|
|
|
|
|
98
|
|
|
$this->output->shouldReceive('writeln')->with('/already initiali[zs]ed/')->once(); |
|
99
|
|
|
$config->shouldNotReceive('write'); |
|
100
|
|
|
|
|
101
|
|
|
$this->configStorage->shouldReceive('isInitialized')->once()->andReturn(true); |
|
102
|
|
|
|
|
103
|
|
|
$this->handle(); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|