Skip to content

Commit

Permalink
Merge pull request #183 from PHPCSStandards/feature/ghactions-remove-…
Browse files Browse the repository at this point in the history
…problem-build

GH Actions: stop running tests against PHP 5.5/Composer 1.x on Windows (and remove work-arounds)
  • Loading branch information
jrfnl committed Jun 25, 2022
2 parents 4b70475 + 3faa61e commit edde434
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 110 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/integrationtest.yml
Expand Up @@ -41,6 +41,13 @@ jobs:
- 'ubuntu-latest'
- 'windows-latest'

exclude:
# Exclude a particularly problematic build.
# @link https://github.com/PHPCSStandards/composer-installer/issues/181
- php: '5.5'
composer: 'v1'
os: 'windows-latest'

include:
# Composer 2.3 drops support for PHP < 7.2, so for PHP 5.4 to 7.1, `v2` will install
# Composer 2.2, for PHP 7.2 and up, `v2` will install Composer 2.3.
Expand Down
18 changes: 14 additions & 4 deletions tests/IntegrationTest/BaseLineTest.php
Expand Up @@ -72,11 +72,10 @@ public function testBaseLineGlobal($phpcsVersion, $expectedStnds)
$this->assertComposerValidates(static::$tempGlobalPath);

// Make sure the plugin runs.
$expectedStdOut = $this->willPluginOutputShow() ? Plugin::MESSAGE_RUNNING_INSTALLER : null;
$this->assertExecute(
'composer global install -v --no-ansi',
0, // Expected exit code.
$expectedStdOut, // Expected stdout.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
Expand Down Expand Up @@ -109,18 +108,29 @@ public function testBaseLineGlobal($phpcsVersion, $expectedStnds)
*/
public function testBaseLineLocal($phpcsVersion, $expectedStnds)
{
if (
$phpcsVersion === PHPCSVersions::MASTER
&& \CLI_PHP_MINOR === '5.5'
&& $this->onWindows() === true
&& substr(\COMPOSER_VERSION, 0, 1) === '1'
) {
$this->markTestSkipped(
'Composer 1.x on Windows with PHP 5.5 does run the plugin when there are no external standards,'
. ' but doesn\'t consistently show this in the logs'
);
}

$config = $this->composerConfig;
$config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion;

$this->writeComposerJsonFile($config, static::$tempLocalPath);
$this->assertComposerValidates(static::$tempLocalPath);

// Make sure the plugin runs.
$expectedStdOut = $this->willPluginOutputShow() ? Plugin::MESSAGE_RUNNING_INSTALLER : null;
$this->assertExecute(
sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)),
0, // Expected exit code.
$expectedStdOut, // Expected stdout.
Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
Expand Down
25 changes: 5 additions & 20 deletions tests/IntegrationTest/InstallUpdateEventsTest.php
Expand Up @@ -87,26 +87,11 @@ public function testPluginRuns($action)
$result = $this->executeCliCommand($command);

$this->assertSame(0, $result['exitcode'], "Exitcode for composer $action did not match 0");

if ($this->willPluginOutputShow() === true) {
$this->assertStringContainsString(
Plugin::MESSAGE_RUNNING_INSTALLER,
$result['stdout'],
"Output from composer $action does not show the plugin as running while it should be."
);
} else {
/*
* Composer edge-case where it doesn't show plugin output.
* Verify the plugin has run by checking via PHPCS.
*/
$result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath);
$this->assertSame(0, $result['exitcode'], 'Exitcode for "--config-show" did not match 0');
$this->assertStringContainsString(
'installed_paths:',
$result['stdout'],
'PHPCS has no paths to external standards registered.'
);
}
$this->assertStringContainsString(
Plugin::MESSAGE_RUNNING_INSTALLER,
$result['stdout'],
"Output from composer $action does not show the plugin as running while it should be."
);
}

/**
Expand Down
94 changes: 37 additions & 57 deletions tests/IntegrationTest/PlayNiceWithScriptsTest.php
Expand Up @@ -86,18 +86,15 @@ public function testScriptsAreNotBlockedFromRunning($command, $expectedOutputs)

$this->assertSame(0, $result['exitcode'], 'Exitcode for initial composer install did not match 0');

if ($this->willPluginOutputShow()) {
$this->assertStringContainsString(
Plugin::MESSAGE_RUNNING_INSTALLER,
$result['stdout'],
'Output from initial composer install missing expected contents.'
);
}
$this->assertStringContainsString(
Plugin::MESSAGE_RUNNING_INSTALLER,
$result['stdout'],
'Output from initial composer install missing expected contents.'
);

$output = $this->willPluginOutputShow() ? $result['stdout'] : $result['stderr'];
$this->assertStringContainsString(
'post-update-cmd successfully run',
$output,
$result['stdout'],
'Output from initial composer install missing expected contents.'
);

Expand Down Expand Up @@ -125,59 +122,42 @@ public function testScriptsAreNotBlockedFromRunning($command, $expectedOutputs)
*/
public function dataScriptsAreNotBlockedFromRunning()
{
$data = array();
$willOutputShow = self::willPluginOutputShow();

$data['install:command'] = array(
'command' => 'composer install',
'expectedOutputs' => array(
'post-install-cmd successfully run',
return array(
'install:command' => array(
'command' => 'composer install',
'expectedOutputs' => array(
'post-install-cmd successfully run',
Plugin::MESSAGE_RUNNING_INSTALLER,
),
),
);
if ($willOutputShow) {
$data['install:command']['expectedOutputs'][] = Plugin::MESSAGE_RUNNING_INSTALLER;
}

$data['update:command'] = array(
'command' => 'composer update',
'expectedOutputs' => array(
'post-update-cmd successfully run',
'update:command' => array(
'command' => 'composer update',
'expectedOutputs' => array(
'post-update-cmd successfully run',
Plugin::MESSAGE_RUNNING_INSTALLER,
),
),
);
if ($willOutputShow) {
$data['update:command']['expectedOutputs'][] = Plugin::MESSAGE_RUNNING_INSTALLER;
}

$data['post-install-cmd:script'] = array(
'command' => 'composer run-script post-install-cmd',
'expectedOutputs' => array(
'post-install-cmd successfully run',
'post-install-cmd:script' => array(
'command' => 'composer run-script post-install-cmd',
'expectedOutputs' => array(
Plugin::MESSAGE_RUNNING_INSTALLER,
'post-install-cmd successfully run',
),
),
);
if ($willOutputShow) {
$data['post-install-cmd:script']['expectedOutputs'][] = Plugin::MESSAGE_RUNNING_INSTALLER;
}

$data['post-update-cmd:script'] = array(
'command' => 'composer run-script post-update-cmd',
'expectedOutputs' => array(
'post-update-cmd successfully run',
'post-update-cmd:script' => array(
'command' => 'composer run-script post-update-cmd',
'expectedOutputs' => array(
Plugin::MESSAGE_RUNNING_INSTALLER,
'post-update-cmd successfully run',
),
),
);
if ($willOutputShow) {
$data['post-update-cmd:script']['expectedOutputs'][] = Plugin::MESSAGE_RUNNING_INSTALLER;
}

$data['install-codestandards:script'] = array(
'command' => 'composer run-script install-codestandards',
'expectedOutputs' => array(
'install-codestandards successfully run',
'install-codestandards:script' => array(
'command' => 'composer run-script install-codestandards',
'expectedOutputs' => array(
Plugin::MESSAGE_RUNNING_INSTALLER,
'install-codestandards successfully run',
),
),
);
if ($willOutputShow) {
$data['install-codestandards:script']['expectedOutputs'][] = Plugin::MESSAGE_RUNNING_INSTALLER;
}

return $data;
}
}
Expand Up @@ -134,12 +134,11 @@ public function testPreexistingValidInstalledPathsConfigIsKeptIntact($phpcsVersi
/*
* 3. Install an external standard.
*/
$expectedStdOut = $this->willPluginOutputShow() ? 'PHP CodeSniffer Config installed_paths set to ' : null;
$command = 'composer global require --dev phpcs-composer-installer/dummy-subdir --no-ansi -v';
$command = 'composer global require --dev phpcs-composer-installer/dummy-subdir --no-ansi -v';
$this->assertExecute(
$command,
0, // Expected exit code.
$expectedStdOut, // Expectation for stdout.
'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout.
null, // No stderr expectation.
'Failed to install Dummy subdir standard.'
);
Expand Down Expand Up @@ -246,15 +245,14 @@ public function testPreexistingInvalidInstalledPathsConfigIsRemoved($phpcsVersio
/*
* 3. Install an external standard.
*/
$expectedStdOut = $this->willPluginOutputShow() ? 'PHP CodeSniffer Config installed_paths set to ' : null;
$command = sprintf(
$command = sprintf(
'composer require --dev phpcs-composer-installer/dummy-subdir --no-ansi -v --working-dir=%s',
escapeshellarg(static::$tempLocalPath)
);
$this->assertExecute(
$command,
0, // Expected exit code.
$expectedStdOut, // Expectation for stdout.
'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout.
null, // No stderr expectation.
'Failed to install Dummy subdir standard.'
);
Expand Down
6 changes: 2 additions & 4 deletions tests/IntegrationTest/RegisterExternalStandardsTest.php
Expand Up @@ -224,11 +224,10 @@ public function testRegisterOneStandardWithMultipleRulesets($phpcsVersion)
$this->writeComposerJsonFile($config, static::$tempLocalPath);

// Install the dependencies and verify that the plugin has run.
$expectedStdOut = $this->willPluginOutputShow() ? 'PHP CodeSniffer Config installed_paths set to ' : null;
$this->assertExecute(
sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)),
0, // Expected exit code.
$expectedStdOut, // Expectation for stdout.
'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
Expand Down Expand Up @@ -293,11 +292,10 @@ public function testRegisterOneStandardInSrcSubdir($phpcsVersion)
$this->writeComposerJsonFile($config, static::$tempGlobalPath);

// Install the dependencies and verify that the plugin has run.
$expectedStdOut = $this->willPluginOutputShow() ? 'PHP CodeSniffer Config installed_paths set to ' : null;
$this->assertExecute(
'composer global install -v --no-ansi',
0, // Expected exit code.
$expectedStdOut, // Expectation for stdout.
'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout.
null, // No stderr expectation.
'Failed to install dependencies.'
);
Expand Down
19 changes: 0 additions & 19 deletions tests/TestCase.php
Expand Up @@ -210,25 +210,6 @@ protected static function onWindows()
return stripos(\PHP_OS, 'WIN') === 0;
}

/**
* Determine whether output expectations can be set for a typical Composer `install`/`update` run.
*
* Composer 1.x on Windows with PHP 5.5 DOES run the plugin, but doesn't consistently show this in the logs.
* This method can be used to still test output expectations in _most_ cases, without failing the tests
* in the rare case they won't show.
*
* It is recommended to only add a call to this method to a test when it has been proven
* to fail without it.
*
* @return bool
*/
protected static function willPluginOutputShow()
{
return ((\CLI_PHP_MINOR === '5.5'
&& self::onWindows() === true
&& strpos(\COMPOSER_VERSION, '1') === 0) === false);
}

/**
* Create a composer.json file based on a given configuration.
*
Expand Down

0 comments on commit edde434

Please sign in to comment.