GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

testGetConfigurationByConfigFileWithValidConfigFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
dl 0
loc 8
rs 9.4285
c 4
b 1
f 2
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Gerrie package.
4
 *
5
 * (c) Andreas Grunwald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Gerrie\Tests\Component\Configuration;
12
13
use Gerrie\Component\Configuration\ConfigurationFactory;
14
15
class ConfigurationFactoryTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    protected function getFixtureConfigFilePath()
19
    {
20
        $configFile  = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
21
        $configFile .= 'Fixture' . DIRECTORY_SEPARATOR . 'DummyConfig.yml';
22
        $configFile = realpath($configFile);
23
24
        return $configFile;
25
    }
26
27
    protected function getDummyInstances()
28
    {
29
        $instances = [
30
            'ssh://[email protected]:29418/',
31
            'https://max.mustermann:[email protected]/r/'
32
        ];
33
34
        return $instances;
35
    }
36
37
    /**
38
     * @expectedException     \RuntimeException
39
     * @expectedExceptionCode 1415381521
40
     */
41
    public function testGetConfigurationByConfigFileWithInvalidConfigFile()
42
    {
43
        ConfigurationFactory::getConfigurationByConfigFile('./doesNotExists.yml');
44
    }
45
46
    public function testGetConfigurationByConfigFileWithValidConfigFile()
47
    {
48
        $configFile = $this->getFixtureConfigFilePath();
49
        $configuration = ConfigurationFactory::getConfigurationByConfigFile($configFile);
50
51
        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
52
        $this->assertEquals('root', $configuration->getConfigurationValue('Database.Username'));
53
    }
54
55
    protected function getArgvInputExtendedMockObject($withConfigFileOption, $withInstancesArguments = false, $dummyInstances = false)
56
    {
57
        $mockedMethods = ['isOptionSet', 'getOption', 'getArgument', 'hasArgument'];
58
        $argvInputExtended = $this->getMock('Gerrie\Component\Console\ArgvInputExtended', $mockedMethods);
59
        $argvInputExtended->expects($this->any())
60
            ->method('isOptionSet')
61
            ->withConsecutive(
62
                array($this->equalTo('config-file')),
63
                array($this->equalTo('database-host')),
64
                array($this->equalTo('database-user')),
65
                array($this->equalTo('database-pass')),
66
                array($this->equalTo('database-port')),
67
                array($this->equalTo('database-name'))
68
            )
69
            ->willReturnOnConsecutiveCalls(
70
                $this->returnValue($withConfigFileOption),
71
                $this->returnValue(true),
72
                $this->returnValue(true),
73
                $this->returnValue(false),
74
                $this->returnValue(true),
75
                $this->returnValue(false)
76
            );
77
78
        $argvInputExtended->expects($this->any())
79
            ->method('getOption')
80
            ->withConsecutive(
81
                array($this->equalTo('database-host')),
82
                array($this->equalTo('database-user')),
83
                array($this->equalTo('database-port'))
84
            )
85
            ->willReturnOnConsecutiveCalls(
86
                $this->returnValue('HOST'),
87
                $this->returnValue('USER'),
88
                $this->returnValue('PORT')
89
            );
90
91
        $argvInputExtended->expects($this->any())
92
            ->method('hasArgument')
93
            ->with($this->equalTo('instances'))
94
            ->will($this->returnValue($withInstancesArguments));
95
96
        if ($withInstancesArguments === true && $dummyInstances === true) {
97
            $instances = $this->getDummyInstances();
98
            $argvInputExtended->expects($this->any())
99
                ->method('getArgument')
100
                ->with($this->equalTo('instances'))
101
                ->will($this->returnValue($instances));
102
        }
103
        /*
104
        if ($withInstancesArguments === false) {
105
106
107
108
109
110
        } else {
111
            $argvInputExtended->expects($this->any())
112
                ->method('hasArgument')
113
                ->with($this->equalTo('instances'))
114
                ->will($this->returnValue(true));
115
        }
116
*/
117
        return $argvInputExtended;
118
    }
119
120
    public function testGetConfigurationByConfigFileAndCommandOptionsAndArguments()
121
    {
122
        $argvInputExtended = $this->getArgvInputExtendedMockObject(true);
123
124
        $configFile = $this->getFixtureConfigFilePath();
125
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);
126
127
        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
128
129
        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
130
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
131
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
132
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
133
        $this->assertEquals('gerrie', $configuration->getConfigurationValue('Database.Name'));
134
    }
135
136
    public function testGetConfigurationByConfigFileAndCommandOptionsAndArgumentsWithoutConfigFileOption()
137
    {
138
        $argvInputExtended = $this->getArgvInputExtendedMockObject(false);
139
140
        $configFile = $this->getFixtureConfigFilePath();
141
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);
142
143
        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
144
145
        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
146
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
147
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
148
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
149
    }
150
151
    public function testGetConfigurationByConfigFileAndCommandOptionsAndArgumentsWitZeroInstanceArgument()
152
    {
153
        $argvInputExtended = $this->getArgvInputExtendedMockObject(false, true);
154
155
        $configFile = $this->getFixtureConfigFilePath();
156
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);
157
158
        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
159
160
        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
161
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
162
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
163
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
164
        $this->assertEquals(null, $configuration->getConfigurationValue('Gerrit.Gerrie'));
165
    }
166
167
    public function testGetConfigurationByConfigFileAndCommandOptionsAndArgumentsWitDummyInstanceArgument()
168
    {
169
        $argvInputExtended = $this->getArgvInputExtendedMockObject(false, true, true);
170
171
        $configFile = $this->getFixtureConfigFilePath();
172
        $configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $argvInputExtended);
173
174
        $this->assertInstanceOf('Gerrie\Component\Configuration\Configuration', $configuration);
175
176
        $this->assertEquals('HOST', $configuration->getConfigurationValue('Database.Host'));
177
        $this->assertEquals('USER', $configuration->getConfigurationValue('Database.Username'));
178
        $this->assertEquals(null, $configuration->getConfigurationValue('Database.Password'));
179
        $this->assertEquals('PORT', $configuration->getConfigurationValue('Database.Port'));
180
        $this->assertInternalType('array', $configuration->getConfigurationValue('Gerrit.Gerrie'));
181
182
        $instances = $this->getDummyInstances();
183
        $this->assertEquals($instances, $configuration->getConfigurationValue('Gerrit.Gerrie'));
184
    }
185
}