Skip to content

Commit

Permalink
Tests: processed review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Mar 5, 2022
1 parent d4f64b8 commit 97ba038
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 36 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -32,11 +32,12 @@
"squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0"
},
"require-dev": {
"ext-json": "*",
"ext-zip": "*",
"composer/composer": "*",
"phpcompatibility/php-compatibility": "^9.0",
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"yoast/phpunit-polyfills": "^1.0.1"
"yoast/phpunit-polyfills": "^1.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
6 changes: 5 additions & 1 deletion phpcs.xml.dist
Expand Up @@ -22,7 +22,11 @@
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>
</rule>

<rule ref="Generic.Formatting.MultipleStatementAlignment"/>
<rule ref="Generic.Formatting.MultipleStatementAlignment">
<properties>
<property name="maxPadding" value="40" />
</properties>
</rule>

<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>*/tests/bootstrap\.php$</exclude-pattern>
Expand Down
16 changes: 3 additions & 13 deletions tests/CreateComposerZipArtifacts.php
Expand Up @@ -92,11 +92,7 @@ class CreateComposerZipArtifacts
public function __construct($artifactDir)
{
// Make sure the directory has a trailing slash.
if (substr($artifactDir, -1) !== '/') {
$artifactDir .= '/';
}

$this->artifactDir = $artifactDir;
$this->artifactDir = rtrim($artifactDir, '/') . '/';
}

/**
Expand All @@ -108,15 +104,9 @@ public function clearOldArtifacts()
{
$di = new DirectoryIterator($this->artifactDir);
foreach ($di as $fileinfo) {
if (
$fileinfo->isDot()
|| $fileinfo->isFile() === false
|| $fileinfo->getExtension() !== 'zip'
) {
continue;
if ($fileinfo->isFile() && $fileinfo->getExtension() === 'zip') {
@unlink($fileinfo->getPathname());
}

@unlink($fileinfo->getPathname());
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/IntegrationTest/BaseLineTest.php
Expand Up @@ -64,7 +64,7 @@ protected function tear_down()
*/
public function testBaseLineGlobal($phpcsVersion, $expectedStnds)
{
$config = $this->composerConfig;
$config = $this->composerConfig;
$config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion;

$this->writeComposerJsonFile($config, static::$tempGlobalPath);
Expand Down Expand Up @@ -108,7 +108,7 @@ public function testBaseLineGlobal($phpcsVersion, $expectedStnds)
*/
public function testBaseLineLocal($phpcsVersion, $expectedStnds)
{
$config = $this->composerConfig;
$config = $this->composerConfig;
$config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion;

$this->writeComposerJsonFile($config, static::$tempLocalPath);
Expand Down
4 changes: 2 additions & 2 deletions tests/IntegrationTest/RegisterExternalStandardsTest.php
Expand Up @@ -56,7 +56,7 @@ protected function tear_down()
*/
public function testRegisterOneStandardGlobal($phpcsVersion)
{
$config = $this->configOneStandard;
$config = $this->configOneStandard;
$config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion;

$this->writeComposerJsonFile($config, static::$tempGlobalPath);
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testRegisterOneStandardGlobal($phpcsVersion)
*/
public function testRegisterOneStandardLocal($phpcsVersion)
{
$config = $this->configOneStandard;
$config = $this->configOneStandard;
$config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion;

$this->writeComposerJsonFile($config, static::$tempLocalPath);
Expand Down
18 changes: 8 additions & 10 deletions tests/PHPCSVersions.php
Expand Up @@ -250,7 +250,7 @@ public static function getRandom($inclMaster = false, $inclNextMajor = false)
/**
* Convert a versions array to an array suitable for use as a PHPUnit dataprovider.
*
* @param array $version Array with PHPCS version numbers as values.
* @param array $versions Array with PHPCS version numbers as values.
*
* @return array Array of PHPCS version identifiers in a format usable for a test data provider.
*/
Expand All @@ -277,8 +277,6 @@ public static function toDataprovider($versions)
*/
public static function getSupportedVersions()
{
$versions = self::$allPhpcsVersions;

/*
* Adjust the list of available versions based on the PHP version on which the tests are run.
*/
Expand Down Expand Up @@ -381,8 +379,8 @@ public static function getStandards($version)
if (
is_string($version) === false
|| (isset(self::$allPhpcsVersions[$version]) === false
&& $version !== PHPCSVersions::MASTER
&& $version !== PHPCSVersions::NEXT_MAJOR)
&& $version !== self::MASTER
&& $version !== self::NEXT_MAJOR)
) {
throw new RuntimeException('The version parameter must be a valid PHPCS version number as a string.');
}
Expand All @@ -395,23 +393,23 @@ public static function getStandards($version)
'Zend',
);

if ($version !== PHPCSVersions::NEXT_MAJOR) {
if ($version !== self::NEXT_MAJOR) {
// The MySource standard is available in PHPCS 2.x and 3.x, but will be removed in 4.0.
$standards[] = 'MySource';
}

if (
$version !== PHPCSVersions::MASTER
&& $version !== PHPCSVersions::NEXT_MAJOR
$version !== self::MASTER
&& $version !== self::NEXT_MAJOR
&& version_compare($version, '3.0.0', '<')
) {
// The PHPCS standard was available in PHPCS 2.x, but has been removed in 3.0.
$standards[] = 'PHPCS';
}

if (
$version === PHPCSVersions::MASTER
|| $version === PHPCSVersions::NEXT_MAJOR
$version === self::MASTER
|| $version === self::NEXT_MAJOR
|| version_compare($version, '3.3.0', '>=')
) {
// The PSR12 standard is available since PHPCS 3.3.0.
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase.php
Expand Up @@ -122,7 +122,7 @@ public function assertComposerValidates($workingDir = '', $file = '')
$command,
0, // Expected exit code.
null, // Expected stdout.
$stderr, // Expected sterr.
$stderr, // Expected stderr.
$message
);
}
Expand Down Expand Up @@ -205,7 +205,7 @@ public function assertExecute(
*/
protected static function onWindows()
{
return strpos(strtoupper(\PHP_OS), 'WIN') === 0;
return stripos(\PHP_OS, 'WIN') === 0;
}

/**
Expand All @@ -224,7 +224,7 @@ protected function willPluginOutputShow()
{
return ((\CLI_PHP_MINOR === '5.5'
&& $this->onWindows() === true
&& substr(\COMPOSER_VERSION, 0, 1) === '1') === false);
&& strpos(\COMPOSER_VERSION, '1') === 0) === false);
}

/**
Expand Down Expand Up @@ -273,7 +273,7 @@ protected static function writeComposerJsonFile($config, $directory)
* Disable TLS when on Windows with Composer 1.x and PHP 5.4.
* @link https://github.com/composer/composer/issues/10495
*/
if (static::onWindows() === true && \CLI_PHP_MINOR === '5.4' && substr(\COMPOSER_VERSION, 0, 1) === '1') {
if (static::onWindows() === true && \CLI_PHP_MINOR === '5.4' && strpos(\COMPOSER_VERSION, '1') === 0) {
$config['config']['disable-tls'] = true;
}

Expand Down Expand Up @@ -484,8 +484,8 @@ protected function maybeStripColors($expected, $actual)
}

if (
strpos($expected, "\033") === false && strpos($actual, "\033") !== false
|| strpos($expected, "\x1b") === false && strpos($actual, "\x1b") !== false
(strpos($expected, "\033") === false && strpos($actual, "\033") !== false)
|| (strpos($expected, "\x1b") === false && strpos($actual, "\x1b") !== false)
) {
$actual = preg_replace('`(?:\\\\033|\\\\x1b)\\\\[[0-9]+(;[0-9]*)[A-Za-z]`', '', $actual);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Expand Up @@ -15,7 +15,7 @@
*/
$tempDir = sys_get_temp_dir() . '/PHPCSPluginTest';
if (file_exists($tempDir) === true) {
if (strpos(strtoupper(\PHP_OS), 'WIN') === 0) {
if (stripos(\PHP_OS, 'WIN') === 0) {
// Windows.
shell_exec(sprintf('rd /s /q %s', escapeshellarg($tempDir)));
} else {
Expand Down

0 comments on commit 97ba038

Please sign in to comment.