/
InvalidPackagesTest.php
116 lines (104 loc) · 3.97 KB
/
InvalidPackagesTest.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
<?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 does not act on packages which are not valid PHPCS standards.
*
* Valid PHPCS standards for the purposes of this plugin, are packages which:
* - have the `phpcodesniffer-standard` type set in their `composer.json` file.
* - contain at least one `ruleset.xml` file.
*
* This test is about Composer and the plugin, so does not need to be tested against multiple PHPCS versions.
* The behaviour also shouldn't differ between a global vs local Composer install, so only testing one type.
*/
final class InvalidPackagesTest extends TestCase
{
private $composerConfigNoRuleset = array(
'name' => 'phpcs-composer-installer/invalid-package-no-ruleset-test',
'require-dev' => array(
'squizlabs/php_codesniffer' => '*',
'phpcs-composer-installer/no-ruleset' => '*',
),
);
private $composerConfigIncorrectType = array(
'name' => 'phpcs-composer-installer/invalid-package-incorrect-type-test',
'require-dev' => array(
'squizlabs/php_codesniffer' => '*',
'phpcs-composer-installer/incorrect-type' => '*',
),
);
/**
* 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 plugin does not set the installed_paths for invalid external PHPCS standards.
*
* @dataProvider dataInvalidPackages
*
* @param array $config The Composer configuration to use.
* @param string $standardName The name of the PHPCS standard which is expected to NOT be registered.
*
* @return void
*/
public function testDontSetInstalledPathsForInvalidPackages($config, $standardName)
{
$this->writeComposerJsonFile($config, 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.'
);
// Make sure the CodeSniffer.conf file does not get created when no (valid) external standards are found.
$this->assertFileDoesNotExist(
static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf'
);
// Make sure that the standard does not show up as registered with PHPCS.
$result = $this->executeCliCommand('"vendor/bin/phpcs" -i', static::$tempLocalPath);
$this->assertSame(0, $result['exitcode'], 'Exitcode for phpcs -i did not match 0');
$this->assertStringNotContainsString(
$standardName,
$result['stdout'],
'Invalid standard registered.'
);
}
/**
* Data provider.
*
* @return array
*/
public function dataInvalidPackages()
{
return array(
'Composer package without ruleset file' => array(
'configName' => $this->composerConfigNoRuleset,
'standardName' => 'NoRuleset',
),
'Composer package with incorrect type' => array(
'configName' => $this->composerConfigIncorrectType,
'standardName' => 'IncorrectType',
),
);
}
}