DeployScriptsTestCase   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 20
Bugs 4 Features 5
Metric Value
wmc 7
c 20
b 4
f 5
lcom 0
cbo 5
dl 0
loc 101
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigurationSet() 0 16 1
A configYamlExists() 0 6 2
A getConfigurationProcessorDouble() 0 7 1
A getSetUpApplication() 0 7 1
A getOutputFromCommand() 0 13 1
A suppressOutput() 0 7 1
1
<?php
2
/**
3
 * Base test case defining generally available methods
4
 */
5
6
namespace Graviton\Deployment;
7
8
use Graviton\Deployment\Command\AbstractCommand;
9
use Symfony\Component\Console\Application;
10
use Symfony\Component\Console\Tester\CommandTester;
11
12
/**
13
 * @author   List of contributors <https://github.com/libgraviton/deploy-scripts/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17
class DeployScriptsTestCase extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * Provides a predefined configuration set.
21
     *
22
     * @return array
23
     */
24
    public static function getConfigurationSet()
25
    {
26
        $configuration = [];
27
        $configuration['cf_bin'] = '/usr/bin/cf';
28
        $configuration['cf_process_timeout'] = 60;
29
        $configuration['cf_username'] = 'Jon';
30
        $configuration['cf_password'] = 'mySecret';
31
        $configuration['cf_org'] = 'ORG';
32
        $configuration['cf_space'] = 'DEV';
33
        $configuration['cf_api_url'] = 'API_URL';
34
        $configuration['cf_domain'] = 'DOMAIN';
35
        $configuration['cf_services']['mongodb'] = 'mongotype';
36
        $configuration['cf_environment_vars']['ERRBIT_API_KEY'] = 'some_secret_key';
37
38
        return $configuration;
39
    }
40
41
    /**
42
     * Determines, if app/config/deploy.yml exists.
43
     *
44
     * @return void
45
     */
46
    public function configYamlExists()
47
    {
48
        if (!file_exists(__DIR__ . '/../../app/config/deploy.yml')) {
49
            $this->markTestSkipped('Configuration file (app/config/deploy.yml) missing.');
50
        }
51
    }
52
53
    /**
54
     * Provides a double of the \Symfony\Component\Config\Definition\Processor
55
     *
56
     * @param array $methods List of methods to be stubbed
57
     *
58
     * @return \PHPUnit_Framework_MockObject_MockObject
59
     */
60
    public function getConfigurationProcessorDouble(array $methods = array())
61
    {
62
        return $this->getMockBuilder('\Symfony\Component\Config\Definition\Processor')
63
            ->disableOriginalConstructor()
64
            ->setMethods($methods)
65
            ->getMock();
66
    }
67
68
    /**
69
     * Provides a symfony application with the provided command setup
70
     *
71
     * @param AbstractCommand $command Instance of a command
72
     *
73
     * @return Application
74
     */
75
    public function getSetUpApplication(AbstractCommand $command)
76
    {
77
        $application = new Application();
78
        $application->add($command);
79
80
        return $application;
81
    }
82
83
    /**
84
     * Provides the output sent to stderr|stdout of a specific command.
85
     *
86
     * @param AbstractCommand $command   Instance of a command
87
     * @param array           $inputArgs Arguments to be passed tot he command via $input.
88
     *
89
     * @return string
90
     */
91
    public function getOutputFromCommand(AbstractCommand $command, array $inputArgs = array())
92
    {
93
        $commandTester = new CommandTester($command);
94
95
        $input = array_merge(array('command' => $command->getName()), $inputArgs);
96
97
        // prevent  command from writing to stdout
98
        ob_start();
99
        $commandTester->execute($input);
100
        ob_end_clean();
101
102
        return $commandTester->getDisplay();
103
    }
104
105
    /**
106
     * suppress output to stdout while test run.
107
     *
108
     * @return void
109
     */
110
    public function suppressOutput()
111
    {
112
        $callback = function () {
113
            // intentionally left blank.
114
        };
115
        $this->setOutputCallback($callback);
116
    }
117
}
118