-
Notifications
You must be signed in to change notification settings - Fork 2
/
ComposerWrapperParamsTest.php
171 lines (152 loc) · 4.8 KB
/
ComposerWrapperParamsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
use BaseTestCase as TestCase;
use org\bovigo\vfs\vfsStream;
class ComposerWrapperParamsTest extends TestCase
{
const COMPOSER_WRAPPER_PARAMS = 'ComposerWrapperParams';
/**
* @test
*/
public function envVariablesHasBiggerPriority()
{
$params = new ComposerWrapperParams();
self::isolatedEnv(
function () use ($params) {
$params->loadReal();
},
array(
"COMPOSER_UPDATE_FREQ" => "101 days",
"COMPOSER_CHANNEL" => 2,
"COMPOSER_DIR" => 'dir_from_env',
),
__DIR__ . '/composer.json_read_config_examples/envVariablesHasBiggerPriority'
);
self::assertSame("101 days", $params->getUpdateFreq());
self::assertSame("2", $params->getChannel());
self::assertSame("dir_from_env", $params->getComposerDir());
}
/**
* @test
*/
public function composerJsonFromEnvVarIsRead()
{
$params = null;
self::isolatedEnv(
function () use (&$params) {
$params = new ComposerWrapperParams();
$params->loadReal();
},
array(
'COMPOSER' => __DIR__ . '/composer.json_read_config_examples/composer.json_is_ignored_when_overridden/composer-from-env.json',
),
__DIR__ . '/composer.json_read_config_examples/composer.json_is_ignored_when_overridden'
);
self::assertSame('101 days', $params->getUpdateFreq());
self::assertSame('2', $params->getChannel());
self::assertSame('dir_from_composer-from-env.json', $params->getComposerDir());
}
/**
* @test
*/
public function updateFreqLoadDefault()
{
$params = $this->loadParamsDefault();
self::assertSame('7 days', $params->getUpdateFreq());
}
public function updateFreqGoodDataProvider()
{
return array(
"some value" => array("40 days", "40 days"),
"negative integer, strange but supported by php engine" => array(-100, "-100"),
);
}
/**
* @test
* @dataProvider updateFreqGoodDataProvider
*/
public function setUpdateFreqHandlesGoodValue($input, $expected)
{
$params = new ComposerWrapperParams();
self::callNonPublic($params, 'setUpdateFreq', array($input));
$actual = $params->getUpdateFreq();
self::assertSame($expected, $actual);
}
public function updateFreqBadDataProvider()
{
return array(
"positive integer value" => array(100),
"negative DateTime modifier" => array("-1 day"),
"zero" => array(0),
"empty string" => array(''),
);
}
/**
* @test
* @dataProvider updateFreqBadDataProvider
*/
public function setUpdateFreqThrowsOnBadValues($input)
{
$this->expectExceptionMessageRegExpCompat('\Exception', '/Wrong update frequency is requested: .*/');
$params = new ComposerWrapperParams();
self::callNonPublic($params, 'setUpdateFreq', array($input));
}
/**
* @test
*/
public function forceMajorVersionLoadDefault()
{
$params = $this->loadParamsDefault();
self::assertNull($params->getChannel());
}
/**
* @test
*/
public function composerDirLoadDefault()
{
$params = $this->loadParamsDefault();
self::assertSame(dirname(self::fullWrapperPath()), $params->getComposerDir());
}
/**
* @test
*/
public function setComposerDirHandlesGoodValues()
{
$params = new ComposerWrapperParams();
self::callNonPublic($params, 'setComposerDir', array(__DIR__));
$actual = $params->getComposerDir();
self::assertSame(__DIR__, $actual);
}
public function composerDirBadDataProvider()
{
return array(
"access denied" => array('/var'),
"doesn't exists" => array(__DIR__ . '/i_dont_exist'),
"non dir" => array(__FILE__),
);
}
/**
* @test
* @dataProvider composerDirBadDataProvider
*/
public function setComposerDirThrowsOnBadValues($input)
{
$this->expectExceptionMessageRegExpCompat('\Exception', '/Wrong composer dir is requested:.*/');
$params = new ComposerWrapperParams();
self::callNonPublic($params, 'setComposerDir', array($input));
}
/**
* @return ComposerWrapperParams
*/
private function loadParamsDefault()
{
return self::isolatedEnv(
function() {
$params = new ComposerWrapperParams();
$params->loadReal();
return $params;
},
array(),
__DIR__ . '/composer.json_read_config_examples/no_composer.json_here'
);
}
}