Skip to content

Commit

Permalink
Add tests for PHP 8.4 (#314)
Browse files Browse the repository at this point in the history
* Add tests for PHP 8.4

* Be more flexible in help test output comparison to account for variations in Symfony version

* Don't bother to fix help tests for very old versions of php

* Previous commit is still a syntax error on PHP 7.1, so it must be fixed if we want to keep running tests on this version at all.
  • Loading branch information
greg-1-anderson authored Dec 13, 2024
1 parent 480fcfc commit 541aaae
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ jobs:
dependencies: highest

- os: ubuntu-latest
php-version: "8.0"
php-version: "8.1"
dependencies: highest
codecov: true
php-ini-values: assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit_buffer_size=4096M, opcache.jit=1205

- os: ubuntu-latest
php-version: "8.3"
php-version: "8.4"
dependencies: highest
codecov: true
php-ini-values: assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit_buffer_size=4096M, opcache.jit=1205
Expand Down
10 changes: 5 additions & 5 deletions tests/AnnotatedCommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,14 @@ function testCommandWithNoArguments()
$this->assertInstanceOf('\Symfony\Component\Console\Command\Command', $command);
$this->assertEquals('command:with-no-arguments', $command->getName());
$this->assertEquals('This command has no arguments--only options', $command->getDescription());
$this->assertEquals("Return a result only if not silent.", $command->getHelp());
$this->assertEquals('command:with-no-arguments [-s|--silent]', $command->getSynopsis());
$this->assertEquals("Return a result only if not silence.", $command->getHelp());
$this->assertEquals('command:with-no-arguments [-s|--silence]', $command->getSynopsis());

$input = new StringInput('command:with-no-arguments');
$this->assertRunCommandViaApplicationEquals($command, $input, 'Hello, world');
$input = new StringInput('command:with-no-arguments -s');
$this->assertRunCommandViaApplicationEquals($command, $input, '');
$input = new StringInput('command:with-no-arguments --silent');
$input = new StringInput('command:with-no-arguments --silence');
$this->assertRunCommandViaApplicationEquals($command, $input, '');
}

Expand All @@ -690,13 +690,13 @@ function testCommandWithShortcutOnAnnotation()
$this->assertEquals('shortcut:on-annotation', $command->getName());
$this->assertEquals('Shortcut on annotation', $command->getDescription());
$this->assertEquals("This command defines the option shortcut on the annotation instead of in the options array.", $command->getHelp());
$this->assertEquals('shortcut:on-annotation [-s|--silent]', $command->getSynopsis());
$this->assertEquals('shortcut:on-annotation [-s|--silence]', $command->getSynopsis());

$input = new StringInput('shortcut:on-annotation');
$this->assertRunCommandViaApplicationEquals($command, $input, 'Hello, world');
$input = new StringInput('shortcut:on-annotation -s');
$this->assertRunCommandViaApplicationEquals($command, $input, '');
$input = new StringInput('shortcut:on-annotation --silent');
$input = new StringInput('shortcut:on-annotation --silence');
$this->assertRunCommandViaApplicationEquals($command, $input, '');
}

Expand Down
41 changes: 20 additions & 21 deletions tests/HelpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ public function addDiscoveredCommands($factory, $commandFiles) {
}
}

function assertRunCommandViaApplicationEquals($cmd, $expectedOutput, $expectedStatusCode = 0)
function assertRunCommandViaApplicationContains($cmd, $containsList, $expectedStatusCode = 0)
{
$input = new StringInput($cmd);
$output = new BufferedOutput();

$statusCode = $this->application->run($input, $output);
$commandOutput = trim($output->fetch());
$commandOutput = $this->simplifyWhitespace($output->fetch());

$expectedOutput = $this->simplifyWhitespace($expectedOutput);
$commandOutput = $this->simplifyWhitespace($commandOutput);

$this->assertEquals($expectedOutput, $commandOutput);
foreach ($containsList as $contains) {
$contains = $this->simplifyWhitespace($contains);
$this->assertStringContainsString($contains, $commandOutput);
}
$this->assertEquals($expectedStatusCode, $statusCode);
}

Expand Down Expand Up @@ -120,7 +120,7 @@ function testHelp()
$expectedFieldMessage = "Select just one field, and force format to 'string'.";
}

$expectedXML = <<<EOT
$expectedXMLBeginning = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<command id="example:table" name="example:table">
<usages>
Expand Down Expand Up @@ -165,9 +165,9 @@ function testHelp()
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>$htmlEncodedHelpMessage</description>\n
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message</description>
</option>
EOT;

$expectedXMLEnd = <<<EOT
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
Expand All @@ -194,14 +194,16 @@ function testHelp()
</command>
EOT;

$this->assertRunCommandViaApplicationEquals('my-help --format=xml example:table', $expectedXML);
$expectedXML = [ $expectedXMLBeginning, $expectedXMLEnd ];

$this->assertRunCommandViaApplicationContains('my-help --format=xml example:table', $expectedXML);

$encodedAnsiMessage = json_encode($expectedAnsiMessage);
$encodedNoAnsiMessage = json_encode($expectedNoAnsiMessage);
$encodedHelpMessage = json_encode(strip_tags($expectedHelpMessage));
$encodedFieldMessage = json_encode($expectedFieldMessage);

$expectedJSON = <<<EOT
$expectedJSONBeginning = <<<EOT
{
"id": "example:table",
"name": "example:table",
Expand Down Expand Up @@ -267,14 +269,9 @@ function testHelp()
"is_multiple": "0",
"description": $encodedHelpMessage
},
"quiet": {
"name": "--quiet",
"shortcut": "-q",
"accept_value": "0",
"is_value_required": "0",
"is_multiple": "0",
"description": "Do not output any message"
},
EOT;

$expectedJSONEnd = <<<EOT
"verbose": {
"name": "--verbose",
"shortcut": "-v",
Expand Down Expand Up @@ -326,6 +323,8 @@ function testHelp()
]
}
EOT;
$this->assertRunCommandViaApplicationEquals('my-help --format=json example:table', $expectedJSON);
$expectedJSON = [ $expectedJSONBeginning, $expectedJSONEnd ];

$this->assertRunCommandViaApplicationContains('my-help --format=json example:table', $expectedJSON);
}
}
14 changes: 7 additions & 7 deletions tests/src/ExampleCommandFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ public function commandWithIOParameters(InputInterface $input, OutputInterface $
/**
* This command has no arguments--only options
*
* Return a result only if not silent.
* Return a result only if not silence.
*
* @option silent Supress output.
* @option silence Supress output.
*/
public function commandWithNoArguments(array $opts = ['silent|s' => false])
public function commandWithNoArguments(array $opts = ['silence|s' => false])
{
if (!$opts['silent']) {
if (!$opts['silence']) {
return "Hello, world";
}
}
Expand All @@ -290,11 +290,11 @@ public function commandWithNoArguments(array $opts = ['silent|s' => false])
* This command defines the option shortcut on the annotation instead of in the options array.
*
* @param $opts The options
* @option silent|s Supress output.
* @option silence|s Supress output.
*/
public function shortcutOnAnnotation(array $opts = ['silent' => false])
public function shortcutOnAnnotation(array $opts = ['silence' => false])
{
if (!$opts['silent']) {
if (!$opts['silence']) {
return "Hello, world";
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/src/alpha/AlphaCommandFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ public function withoutAnnotations()
*
* Return a result only if not silent.
*
* @option silent Supress output.
* @option silence Supress output.
*/
public function commandWithOneOptionalArgument($who = 'world', $opts = ['silent|s' => false])
public function commandWithOneOptionalArgument($who = 'world', $opts = ['silence|s' => false])
{
if (!$opts['silent']) {
if (!$opts['silence']) {
return "Hello, $who";
}
}
Expand Down

0 comments on commit 541aaae

Please sign in to comment.