-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
InstalledPathsOrderTest.php
119 lines (103 loc) · 4.51 KB
/
InstalledPathsOrderTest.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
<?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 that the plugin always registers the installed_paths in the same order.
*
* This test is about Composer and the plugin, so does not need to be tested against multiple PHPCS versions.
*
* @link https://github.com/PHPCSStandards/composer-installer/issues/125
* @link https://github.com/PHPCSStandards/composer-installer/pull/126
*/
final class InstalledPathsOrderTest extends TestCase
{
private $composerConfigA = array(
'name' => 'phpcs-composer-installer/sort-order-test',
'require-dev' => array(
'phpcs-composer-installer/dummy-subdir' => '*',
'phpcs-composer-installer/multistandard' => '*',
'phpcs-composer-installer/dummy-src' => '*',
),
'minimum-stability' => 'dev',
'prefer-stable' => true,
);
private $composerConfigB = array(
'name' => 'phpcs-composer-installer/sort-order-test',
'require-dev' => array(
'phpcs-composer-installer/multistandard' => '*',
'phpcs-composer-installer/dummy-src' => '*',
'phpcs-composer-installer/dummy-subdir' => '*',
),
'minimum-stability' => 'dev',
'prefer-stable' => true,
);
/**
* Set up test environment before each test.
*/
protected function set_up()
{
$this->createTestEnvironment();
}
/**
* Clean up after each test.
*/
protected function tear_down()
{
$this->removeTestEnvironment();
}
/**
* Test that the paths registered through the plugin are always registered in the same (sort) order.
*
* @return void
*/
public function testInstalledPathsAreAlwaysRegisteredInSameOrder()
{
/*
* 1. Install using ConfigA in the Composer global directory.
*/
$this->writeComposerJsonFile($this->composerConfigA, static::$tempGlobalPath);
// 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.'
);
/*
* 2. Install using ConfigB in the Composer local directory.
*/
$this->writeComposerJsonFile($this->composerConfigB, static::$tempLocalPath);
// 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.'
);
/*
* 3. Retrieve the installed paths from both and compare to ensure the order is the same.
*/
$globalPaths = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempGlobalPath);
$this->assertSame(0, $globalPaths['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (global)');
$localPaths = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath);
$this->assertSame(0, $localPaths['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (local)');
// Get the installed paths setting from the config.
$this->assertSame(1, preg_match('`installed_paths:\s+([^\n\r]+)\s+`', $globalPaths['stdout'], $matchGlobal));
$this->assertSame(1, preg_match('`installed_paths:\s+([^\n\r]+)\s+`', $localPaths['stdout'], $matchLocal));
// Remove any differences caused by global vs local paths and absolute vs relative paths.
$matchGlobal = str_replace(array(static::$tempGlobalPath . '/vendor', '../..'), '', $matchGlobal[1]);
$matchLocal = str_replace(array(static::$tempLocalPath . '/vendor', '../..'), '', $matchLocal[1]);
// Verify that the paths are registered in the same order both times.
$this->assertSame($matchGlobal, $matchLocal);
}
}