Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayNiceWithScriptsTest: wrap output expectation in condition #179

Merged
merged 2 commits into from May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 57 additions & 37 deletions tests/IntegrationTest/PlayNiceWithScriptsTest.php
Expand Up @@ -86,15 +86,18 @@ public function testScriptsAreNotBlockedFromRunning($command, $expectedOutputs)

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

$this->assertStringContainsString(
Plugin::MESSAGE_RUNNING_INSTALLER,
$result['stdout'],
'Output from initial composer install missing expected contents.'
);
if ($this->willPluginOutputShow()) {
$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',
$result['stdout'],
$output,
'Output from initial composer install missing expected contents.'
);

Expand Down Expand Up @@ -122,42 +125,59 @@ public function testScriptsAreNotBlockedFromRunning($command, $expectedOutputs)
*/
public function dataScriptsAreNotBlockedFromRunning()
{
return array(
'install:command' => array(
'command' => 'composer install',
'expectedOutputs' => array(
'post-install-cmd successfully run',
Plugin::MESSAGE_RUNNING_INSTALLER,
),
$data = array();
$willOutputShow = self::willPluginOutputShow();

$data['install:command'] = array(
'command' => 'composer install',
'expectedOutputs' => array(
'post-install-cmd successfully run',
),
'update:command' => array(
'command' => 'composer update',
'expectedOutputs' => array(
'post-update-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',
),
'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['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-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-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',
),
'install-codestandards:script' => array(
'command' => 'composer run-script install-codestandards',
'expectedOutputs' => array(
Plugin::MESSAGE_RUNNING_INSTALLER,
'install-codestandards 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',
),
);
if ($willOutputShow) {
$data['install-codestandards:script']['expectedOutputs'][] = Plugin::MESSAGE_RUNNING_INSTALLER;
}

return $data;
}
}
4 changes: 2 additions & 2 deletions tests/TestCase.php
Expand Up @@ -220,10 +220,10 @@ protected static function onWindows()
*
* @return bool
*/
protected function willPluginOutputShow()
protected static function willPluginOutputShow()
{
return ((\CLI_PHP_MINOR === '5.5'
&& $this->onWindows() === true
&& self::onWindows() === true
&& strpos(\COMPOSER_VERSION, '1') === 0) === false);
}

Expand Down