From 52733ae110564751ec5c5535f7c5e624bc14518f Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 13 Dec 2024 08:12:28 -0800 Subject: [PATCH 1/4] Add tests for PHP 8.4 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fb15b5..f29ed34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 From b9754a2748b04feb62e87e7d074d7b2e1f53747f Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 13 Dec 2024 10:21:31 -0800 Subject: [PATCH 2/4] Be more flexible in help test output comparison to account for variations in Symfony version --- tests/AnnotatedCommandFactoryTest.php | 10 +++---- tests/HelpTest.php | 41 ++++++++++++--------------- tests/src/ExampleCommandFile.php | 14 ++++----- tests/src/alpha/AlphaCommandFile.php | 6 ++-- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/tests/AnnotatedCommandFactoryTest.php b/tests/AnnotatedCommandFactoryTest.php index 574a669..6cd7ba9 100644 --- a/tests/AnnotatedCommandFactoryTest.php +++ b/tests/AnnotatedCommandFactoryTest.php @@ -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, ''); } @@ -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, ''); } diff --git a/tests/HelpTest.php b/tests/HelpTest.php index 3174b0a..fbe827c 100644 --- a/tests/HelpTest.php +++ b/tests/HelpTest.php @@ -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); } @@ -120,7 +120,8 @@ function testHelp() $expectedFieldMessage = "Select just one field, and force format to 'string'."; } - $expectedXML = << @@ -165,9 +166,8 @@ function testHelp() - +EOT, +<< Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug @@ -192,16 +192,17 @@ function testHelp() docs-tables -EOT; +EOT]; - $this->assertRunCommandViaApplicationEquals('my-help --format=xml example:table', $expectedXML); + $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 = <<assertRunCommandViaApplicationEquals('my-help --format=json example:table', $expectedJSON); +EOT]; + $this->assertRunCommandViaApplicationContains('my-help --format=json example:table', $expectedJSON); } } diff --git a/tests/src/ExampleCommandFile.php b/tests/src/ExampleCommandFile.php index 83b1e49..ee83681 100644 --- a/tests/src/ExampleCommandFile.php +++ b/tests/src/ExampleCommandFile.php @@ -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"; } } @@ -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"; } } diff --git a/tests/src/alpha/AlphaCommandFile.php b/tests/src/alpha/AlphaCommandFile.php index 051e1b8..8cd7573 100644 --- a/tests/src/alpha/AlphaCommandFile.php +++ b/tests/src/alpha/AlphaCommandFile.php @@ -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"; } } From b02e196493676371825cf05bacb90ad4e54a60fb Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 13 Dec 2024 10:30:30 -0800 Subject: [PATCH 3/4] Don't bother to fix help tests for very old versions of php --- tests/HelpTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/HelpTest.php b/tests/HelpTest.php index fbe827c..f3412ea 100644 --- a/tests/HelpTest.php +++ b/tests/HelpTest.php @@ -96,6 +96,10 @@ function simplifyWhitespace($data) function testHelp() { + if (version_compare(PHP_VERSION, '7.4.0', '<')) { + $this->markTestSkipped("Help tests don't work on very old versions of PHP; we expect help itself is still working, but support for these old versions is limited."); + } + $symfonyConsoleVersion = ltrim(InstalledVersions::getPrettyVersion('symfony/console'), 'v'); if (version_compare($symfonyConsoleVersion, '5.3.0', '>=')) { $expectedAnsiMessage = 'Force (or disable --no-ansi) ANSI output'; From 7f71789c668f3cb185918099b72cef91798793b5 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 13 Dec 2024 10:36:01 -0800 Subject: [PATCH 4/4] 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. --- tests/HelpTest.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/HelpTest.php b/tests/HelpTest.php index f3412ea..8dfd234 100644 --- a/tests/HelpTest.php +++ b/tests/HelpTest.php @@ -96,10 +96,6 @@ function simplifyWhitespace($data) function testHelp() { - if (version_compare(PHP_VERSION, '7.4.0', '<')) { - $this->markTestSkipped("Help tests don't work on very old versions of PHP; we expect help itself is still working, but support for these old versions is limited."); - } - $symfonyConsoleVersion = ltrim(InstalledVersions::getPrettyVersion('symfony/console'), 'v'); if (version_compare($symfonyConsoleVersion, '5.3.0', '>=')) { $expectedAnsiMessage = 'Force (or disable --no-ansi) ANSI output'; @@ -124,8 +120,7 @@ function testHelp() $expectedFieldMessage = "Select just one field, and force format to 'string'."; } - $expectedXML = [ -<< @@ -170,8 +165,9 @@ function testHelp() -EOT, -<< Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug @@ -196,7 +192,9 @@ function testHelp() docs-tables -EOT]; +EOT; + + $expectedXML = [ $expectedXMLBeginning, $expectedXMLEnd ]; $this->assertRunCommandViaApplicationContains('my-help --format=xml example:table', $expectedXML); @@ -205,8 +203,7 @@ function testHelp() $encodedHelpMessage = json_encode(strip_tags($expectedHelpMessage)); $encodedFieldMessage = json_encode($expectedFieldMessage); - $expectedJSON = [ -<<assertRunCommandViaApplicationContains('my-help --format=json example:table', $expectedJSON); } }