-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathHandlerTest.php
234 lines (207 loc) · 6.04 KB
/
HandlerTest.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* @file
* Contains \DrupalComposer\DrupalScaffold\Tests\HandlerTest.
*/
namespace DrupalComposer\DrupalScaffold\Tests;
use Composer\Composer;
use Composer\Config;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Package\Package;
use Composer\Package\RootPackage;
use Composer\Repository\RepositoryManager;
use Composer\Repository\WritableArrayRepository;
use DrupalComposer\DrupalScaffold\Handler;
class HandlerTest extends \PHPUnit_Framework_TestCase {
private static $eightFourTwoIncludes = [
'.csslintrc' => '.csslintrc',
'.editorconfig' => '.editorconfig',
'.eslintignore' => '.eslintignore',
'.eslintrc.json' => '.eslintrc.json',
'.gitattributes' => '.gitattributes',
'.htaccess' => '.htaccess',
'index.php' => 'index.php',
'robots.txt' => 'robots.txt',
'sites/default/default.services.yml' => 'sites/default/default.services.yml',
'sites/default/default.settings.php' => 'sites/default/default.settings.php',
'sites/development.services.yml' => 'sites/development.services.yml',
'sites/example.settings.local.php' => 'sites/example.settings.local.php',
'sites/example.sites.php' => 'sites/example.sites.php',
'update.php' => 'update.php',
'web.config' => 'web.config',
];
private function getComposer($drupalVersion, array $extra = []) {
$package = new RootPackage('test', '1.0.0', '1.0.0');
$package->setExtra($extra);
$composer = new Composer();
$composer->setPackage($package);
$io = new NullIO();
$config = new Config(false);
$drupalPackage = new Package('drupal/core', $drupalVersion, $drupalVersion);
$localRepository = new WritableArrayRepository();
$localRepository->addPackage($drupalPackage);
$repositoryManager = new RepositoryManager($io, $config);
$repositoryManager->setLocalRepository($localRepository);
$composer->setRepositoryManager($repositoryManager);
return $composer;
}
public function getGetIncludesTests() {
return [
[
'8.4.2',
[],
self::$eightFourTwoIncludes
],
[
'8.4.2',
[
'drupal-scaffold' => [
'includes' => ['.csslintrc']
]
],
self::$eightFourTwoIncludes
],
[
'8.4.2',
[
'drupal-scaffold' => [
'includes' => ['.csslintrc' => 'foo']
]
],
['.csslintrc' => 'foo'] + self::$eightFourTwoIncludes
],
];
}
/**
* @dataProvider getGetIncludesTests
*/
public function testGetIncludes($drupalVersion, $extra, $expected) {
$handler = new DummyHandler($this->getComposer($drupalVersion, $extra), new NullIO());
$actual = $handler->doGetIncludes();
$this->assertEquals($expected, $actual);
}
public function getGetInitialTests() {
return [
['8.4.2', []]
];
}
/**
* @dataProvider getGetInitialTests
*/
public function testGetInitial($drupalVersion, $expected) {
$io = $this->prophesize(IOInterface::class);
$handler = new DummyHandler($this->getComposer($drupalVersion), $io->reveal());
$actual = $handler->doGetInitial();
$this->assertEquals($expected, $actual);
}
public function getGetExcludesTests() {
return [
['8.4.2', []]
];
}
/**
* @dataProvider getGetExcludesTests
*/
public function testGetExcludes($drupalVersion, $expected) {
$io = $this->prophesize(IOInterface::class);
$handler = new DummyHandler($this->getComposer($drupalVersion), $io->reveal());
$actual = $handler->doGetExcludes();
$this->assertEquals($expected, $actual);
}
public function getGetFilesTests() {
return [
[
'8.4.2',
[],
self::$eightFourTwoIncludes,
'Default includes are returned if no excludes are specified.'
],
[
'8.4.2',
[
'drupal-scaffold' => [
'excludes' => ['.csslintrc']
]
],
array_diff_key(self::$eightFourTwoIncludes, ['.csslintrc' => NULL]),
'Excludes are removed from files when they are specified as a simple array',
],
[
'8.4.2',
// Nobody will do this, but we want to make sure it doesn't fail.
[
'drupal-scaffold' => [
'excludes' => [
'.csslintrc' => 'foo'
]
]
],
array_diff_key(self::$eightFourTwoIncludes, ['.csslintrc' => '']),
'Excludes are removed from files when they are specified as an associative array',
],
[
'8.4.2',
['drupal-scaffold' => ['omit-defaults' => true]],
[],
'Defaults can be omitted.',
],
[
'8.4.2',
[
'drupal-scaffold' => [
'omit-defaults' => true,
'includes' => [
'foo' => 'bar',
],
]
],
['foo' => 'bar'],
'New includes will be considered'
],
[
'8.4.2',
[
'drupal-scaffold' => [
'omit-defaults' => true,
'includes' => [
'foo' => 'bar',
],
'excludes' => ['foo'],
]
],
[],
'New includes will be considered for exclusion'
]
];
}
/**
* Test that the getFiles method considers excludes.
*
* @dataProvider getGetFilesTests
*/
public function testGetFiles($drupalVersion, $extra, $expected, $message = '') {
$io = $this->prophesize(IOInterface::class);
$handler = new DummyHandler($this->getComposer($drupalVersion, $extra), $io->reveal());
$actual = $handler->doGetFiles();
$this->assertEquals($expected, $actual, $message);
}
}
/**
* Extends handler to expose public methods that can be used for testing
* internal behavior.
*/
class DummyHandler extends Handler {
public function doGetFiles() {
return $this->getFiles();
}
public function doGetIncludes() {
return $this->getIncludes();
}
public function doGetExcludes() {
return $this->getExcludes();
}
public function doGetInitial() {
return $this->getInitial();
}
}