|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Validates command to authorize to a Cloud Foundry. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\Deployment\Tests\Command\CloudFoundry; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\Deployment\Configuration; |
|
9
|
|
|
use Graviton\Deployment\Deployment; |
|
10
|
|
|
use Graviton\Deployment\DeployScriptsTestCase; |
|
11
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
12
|
|
|
use Symfony\Component\Config\FileLocator; |
|
13
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/deploy-scripts/graphs/contributors> |
|
17
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
18
|
|
|
* @link http://swisscom.ch |
|
19
|
|
|
*/ |
|
20
|
|
|
class CommandWithArgumentsTest extends DeployScriptsTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @dataProvider configureCommandProvider |
|
24
|
|
|
* |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $cmd Command to be tested. |
|
27
|
|
|
* @param array $commandArgs List of argumenst to instantiate the command. |
|
28
|
|
|
* @param string $commandName Name of the command. |
|
29
|
|
|
* @param string $commandDescription Input arguments for the command. |
|
30
|
|
|
* |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testConfigure($cmd, array $commandArgs, $commandName, $commandDescription) |
|
35
|
|
|
{ |
|
36
|
|
|
$reflection = new \ReflectionClass($cmd); |
|
37
|
|
|
$command = $reflection->newInstanceArgs($commandArgs); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertAttributeEquals($commandName, 'name', $command); |
|
40
|
|
|
$this->assertAttributeEquals($commandDescription, 'description', $command); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function configureCommandProvider() |
|
47
|
|
|
{ |
|
48
|
|
|
$locator = new FileLocator(__DIR__ . '/../../Resources/config'); |
|
49
|
|
|
$configuration = new Configuration(new Processor(), $locator); |
|
50
|
|
|
$deploymentHandler = new Deployment(new ProcessBuilder()); |
|
51
|
|
|
|
|
52
|
|
|
return array( |
|
53
|
|
|
'check application command' => array( |
|
54
|
|
|
'\Graviton\Deployment\Command\CloudFoundry\CheckApplicationCommand', |
|
55
|
|
|
array($configuration), |
|
56
|
|
|
'graviton:deployment:cf:checkApplication', |
|
57
|
|
|
'Determines, if a special CF application is alive.' |
|
58
|
|
|
), |
|
59
|
|
|
'deploy command' => array( |
|
60
|
|
|
'\Graviton\Deployment\Command\CloudFoundry\DeployCommand', |
|
61
|
|
|
array($deploymentHandler, $configuration), |
|
62
|
|
|
'graviton:deployment:cf:deploy', |
|
63
|
|
|
'Deploys an application to a CF instance.' |
|
64
|
|
|
), |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @dataProvider executeCommandProvider |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $cmd Command to be tested. |
|
72
|
|
|
* @param array $commandArgs List of arguments to instantiate the command. |
|
73
|
|
|
* @param string $commandName Name of the command. |
|
74
|
|
|
* @param array $inputArgs Input arguments for the command. |
|
75
|
|
|
* @param string $expected Console output. |
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testExecute($cmd, array $commandArgs, $commandName, array $inputArgs, $expected) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->configYamlExists(); |
|
82
|
|
|
$this->suppressOutput(); |
|
83
|
|
|
|
|
84
|
|
|
$reflection = new \ReflectionClass($cmd); |
|
85
|
|
|
$command = $reflection->newInstanceArgs($commandArgs); |
|
86
|
|
|
|
|
87
|
|
|
$application = $this->getSetUpApplication($command); |
|
88
|
|
|
$command = $application->find($commandName); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertContains($expected, $this->getOutputFromCommand($command, $inputArgs)); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
|
|
public function executeCommandProvider() |
|
97
|
|
|
{ |
|
98
|
|
|
$locator = new FileLocator(__DIR__ . '/../../Resources/config'); |
|
99
|
|
|
$configuration = new Configuration(new Processor(), $locator); |
|
100
|
|
|
$deploymentHandler = new Deployment(new ProcessBuilder()); |
|
101
|
|
|
|
|
102
|
|
|
return array( |
|
103
|
|
|
'check application command' => array( |
|
104
|
|
|
'\Graviton\Deployment\Command\CloudFoundry\CheckApplicationCommand', |
|
105
|
|
|
array($configuration), |
|
106
|
|
|
'graviton:deployment:cf:checkApplication', |
|
107
|
|
|
array( |
|
108
|
|
|
'applicationName' => 'graviton-develop', |
|
109
|
|
|
'slice' => 'blue' |
|
110
|
|
|
), |
|
111
|
|
|
'Application health check. Stated messages:' |
|
112
|
|
|
), |
|
113
|
|
|
'deploy command' => array( |
|
114
|
|
|
'\Graviton\Deployment\Command\CloudFoundry\DeployCommand', |
|
115
|
|
|
array($deploymentHandler, $configuration), |
|
116
|
|
|
'graviton:deployment:cf:deploy', |
|
117
|
|
|
array( |
|
118
|
|
|
'applicationName' => 'graviton-develop' |
|
119
|
|
|
), |
|
120
|
|
|
'Deploying application (graviton-develop-unstable) to a Cloud Foundry instance.' |
|
121
|
|
|
), |
|
122
|
|
|
); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|