From 97ba038345c7666a01781874b69358a8101ab060 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 6 Feb 2022 15:51:13 +0100 Subject: [PATCH] Tests: processed review feedback --- composer.json | 3 ++- phpcs.xml.dist | 6 +++++- tests/CreateComposerZipArtifacts.php | 16 +++------------- tests/IntegrationTest/BaseLineTest.php | 4 ++-- .../RegisterExternalStandardsTest.php | 4 ++-- tests/PHPCSVersions.php | 18 ++++++++---------- tests/TestCase.php | 12 ++++++------ tests/bootstrap.php | 2 +- 8 files changed, 29 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index df05073f..ba8cf7c0 100644 --- a/composer.json +++ b/composer.json @@ -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, diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0bbe32ed..493a03ea 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -22,7 +22,11 @@ - + + + + + */tests/bootstrap\.php$ diff --git a/tests/CreateComposerZipArtifacts.php b/tests/CreateComposerZipArtifacts.php index bc796a28..202cdefe 100644 --- a/tests/CreateComposerZipArtifacts.php +++ b/tests/CreateComposerZipArtifacts.php @@ -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, '/') . '/'; } /** @@ -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()); } } diff --git a/tests/IntegrationTest/BaseLineTest.php b/tests/IntegrationTest/BaseLineTest.php index 83356543..8c635346 100644 --- a/tests/IntegrationTest/BaseLineTest.php +++ b/tests/IntegrationTest/BaseLineTest.php @@ -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); @@ -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); diff --git a/tests/IntegrationTest/RegisterExternalStandardsTest.php b/tests/IntegrationTest/RegisterExternalStandardsTest.php index 57125ac9..e2841dd6 100644 --- a/tests/IntegrationTest/RegisterExternalStandardsTest.php +++ b/tests/IntegrationTest/RegisterExternalStandardsTest.php @@ -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); @@ -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); diff --git a/tests/PHPCSVersions.php b/tests/PHPCSVersions.php index 18c884c9..51b65842 100644 --- a/tests/PHPCSVersions.php +++ b/tests/PHPCSVersions.php @@ -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. */ @@ -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. */ @@ -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.'); } @@ -395,14 +393,14 @@ 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. @@ -410,8 +408,8 @@ public static function getStandards($version) } 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. diff --git a/tests/TestCase.php b/tests/TestCase.php index 2375b1c0..57b00c04 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -122,7 +122,7 @@ public function assertComposerValidates($workingDir = '', $file = '') $command, 0, // Expected exit code. null, // Expected stdout. - $stderr, // Expected sterr. + $stderr, // Expected stderr. $message ); } @@ -205,7 +205,7 @@ public function assertExecute( */ protected static function onWindows() { - return strpos(strtoupper(\PHP_OS), 'WIN') === 0; + return stripos(\PHP_OS, 'WIN') === 0; } /** @@ -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); } /** @@ -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; } @@ -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); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b2c676f4..52c18a2a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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 {