-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
RemovePluginTest.php
281 lines (254 loc) · 10.7 KB
/
RemovePluginTest.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
/**
* This file is part of the Dealerdirect PHP_CodeSniffer Standards
* Composer Installer Plugin package.
*
* @copyright 2022 PHPCodeSniffer Composer Installer Contributors
* @license MIT
*/
namespace Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Tests\IntegrationTest;
use Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin;
use Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Tests\TestCase;
/**
* Test plugin does not throw errors when the plugin is still in memory, but PHPCS and the plugin are uninstalled.
*
* These tests verify:
* - That the plugin exits with error code 0 when PHPCS and the plugin are uninstalled due to a no-dev install.
* - That the plugin exits with error code 0 when the standard which required the plugin is uninstalled.
*
* @link https://github.com/PHPCSStandards/composer-installer/issues/103
* @link https://github.com/PHPCSStandards/composer-installer/pull/104
* @link https://gist.github.com/Potherca/49bdf3fb36d2c03c643c28084d74e4a7
*/
final class RemovePluginTest extends TestCase
{
private $composerConfigRequireDev = array(
'name' => 'phpcs-composer-installer/remove-phpcs-test',
'require-dev' => array(
'phpcs-composer-installer/multistandard' => '*',
),
);
private $composerConfigRequire = array(
'name' => 'phpcs-composer-installer/remove-phpcs-test',
'require' => array(
'phpcs-composer-installer/multistandard' => '*',
),
);
/**
* Set up test environment before each test.
*/
protected function set_up()
{
$this->createTestEnvironment();
}
/**
* Clean up after each test.
*/
protected function tear_down()
{
$this->removeTestEnvironment();
}
/**
* Helper method to get the stdout expectation for when the plugin is uninstalled.
*
* As of Composer 2.0.0, plugins which have been uninstalled will not run anymore
* after the uninstall (which is good).
* It is unclear which particular change this can be attributed to.
*
* @return string
*/
private function getUninstallStdOutExpectation()
{
if (strpos(\COMPOSER_VERSION, '1') === 0) {
return Plugin::MESSAGE_PLUGIN_UNINSTALLED;
}
return '';
}
/**
* Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when PHPCS and the plugin
* were installed via --dev and a no-dev install is run, which removes the plugin and PHPCS.
*
* @return void
*/
public function testRemovePHPCSViaNoDevGlobal()
{
$this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempGlobalPath);
// Install dependencies and make sure the plugin runs.
$this->assertExecute(
'composer global install -v --no-ansi',
0, // Expected exit code.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
/*
* Switch to a no-dev install, which should remove the plugin, but the
* plugin will still be loaded in memory, so we need to make sure it doesn't
* throw errors.
*/
$this->assertExecute(
'composer global install --no-dev -v --no-ansi',
0, // Expected exit code.
$this->getUninstallStdOutExpectation(), // Expected stdout.
null, // No stderr expectation.
'Uninstall by switching to no-dev did not meet expectations.'
);
}
/**
* Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when PHPCS and the plugin
* were installed via --dev and a no-dev install is run, which removes the plugin and PHPCS.
*
* @return void
*/
public function testRemovePHPCSViaNoDevLocal()
{
$this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempLocalPath);
// Install dependencies and make sure the plugin runs.
$this->assertExecute(
sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)),
0, // Expected exit code.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
/*
* Switch to a no-dev install, which should remove the plugin, but the
* plugin will still be loaded in memory, so we need to make sure it exits with 0.
*/
$this->assertExecute(
sprintf('composer install --no-dev -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)),
0, // Expected exit code.
$this->getUninstallStdOutExpectation(), // Expected stdout.
null, // No stderr expectation.
'Uninstall by switching to no-dev did not meet expectations.'
);
}
/**
* Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS
* and the plugin when installed via require-dev by removing the dependency which installed it.
*
* @return void
*/
public function testRemovePHPCSViaDevUninstallGlobal()
{
$this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempGlobalPath);
// Install dependencies and make sure the plugin runs.
$this->assertExecute(
'composer global install -v --no-ansi',
0, // Expected exit code.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
/*
* Remove the dev dependency which caused the install of the plugin.
* This should also remove the plugin, but the plugin will still be loaded in memory,
* so we need to make sure it exits with 0.
*/
$this->assertExecute(
'composer global remove --dev phpcs-composer-installer/multistandard -v --no-ansi',
0, // Expected exit code.
$this->getUninstallStdOutExpectation(), // Expected stdout.
null, // No stderr expectation.
'Uninstall of dev dependency did not meet expectations.'
);
}
/**
* Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS
* and the plugin when installed via require-dev by removing the dependency which installed it.
*
* @return void
*/
public function testRemovePHPCSViaDevUninstallLocal()
{
$this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempLocalPath);
// Install dependencies and make sure the plugin runs.
$this->assertExecute(
sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)),
0, // Expected exit code.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
/*
* Remove the dev dependency which caused the install of the plugin.
* This should also remove the plugin, but the plugin will still be loaded in memory,
* so we need to make sure it exits with 0.
*/
$command = sprintf(
'composer remove --dev phpcs-composer-installer/multistandard -v --no-ansi --working-dir=%s',
escapeshellarg(static::$tempLocalPath)
);
$this->assertExecute(
$command,
0, // Expected exit code.
$this->getUninstallStdOutExpectation(), // Expected stdout.
null, // No stderr expectation.
'Uninstall of dev dependency did not meet expectations.'
);
}
/**
* Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS
* and the plugin when installed via require by removing the dependency which installed it.
*
* @return void
*/
public function testRemovePHPCSViaNoDevUninstallGlobal()
{
$this->writeComposerJsonFile($this->composerConfigRequire, static::$tempGlobalPath);
// Install dependencies and make sure the plugin runs.
$this->assertExecute(
'composer global install -v --no-ansi',
0, // Expected exit code.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
/*
* Remove the dev dependency which caused the install of the plugin.
* This should also remove the plugin, but the plugin will still be loaded in memory,
* so we need to make sure it exits with 0.
*/
$this->assertExecute(
'composer global remove phpcs-composer-installer/multistandard -v --no-ansi',
0, // Expected exit code.
$this->getUninstallStdOutExpectation(), // Expected stdout.
null, // No stderr expectation.
'Uninstall of no-dev dependency did not meet expectations.'
);
}
/**
* Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS
* and the plugin when installed via require by removing the dependency which installed it.
*
* @return void
*/
public function testRemovePHPCSViaNoDevUninstallLocal()
{
$this->writeComposerJsonFile($this->composerConfigRequire, static::$tempLocalPath);
// Install dependencies and make sure the plugin runs.
$this->assertExecute(
sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)),
0, // Expected exit code.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
/*
* Remove the dev dependency which caused the install of the plugin.
* This should also remove the plugin, but the plugin will still be loaded in memory,
* so we need to make sure it exits with 0.
*/
$command = sprintf(
'composer remove phpcs-composer-installer/multistandard -v --no-ansi --working-dir=%s',
escapeshellarg(static::$tempLocalPath)
);
$this->assertExecute(
$command,
0, // Expected exit code.
$this->getUninstallStdOutExpectation(), // Expected stdout.
null, // No stderr expectation.
'Uninstall of no-dev dependency did not meet expectations.'
);
}
}