From 8bc47ee1cecb71a3b156d934181b6fff4221a176 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 29 Mar 2024 16:39:24 +0200 Subject: [PATCH] PHPUnit 10 support + testing on PHP 8+ Lift restriction on used "symfony/process" component version Correct "symfony/process"-related tests --- .github/workflows/main.yml | 2 +- composer.json | 3 +-- composer.lock | 2 +- .../CommitMessage/CommitMessageBuilder.php | 2 +- .../Repository/Connector/Connector.php | 2 +- tests/SVNBuddy/AbstractTestCase.php | 17 +++++++++++++ .../Config/AbstractConfigSettingTestCase.php | 6 ++--- .../Config/ArrayConfigSettingTest.php | 24 +++++++++---------- .../Config/ChoiceConfigSettingTest.php | 18 +++++++------- .../Config/IntegerConfigSettingTest.php | 18 +++++++------- .../Config/StringConfigSettingTest.php | 18 +++++++------- .../AbstractDatabaseAwareTestCase.php | 3 ++- .../MergeSourceDetectorAggregatorTest.php | 12 ++++------ .../Connector/CommandFactoryTest.php | 2 +- .../Repository/Connector/CommandTest.php | 8 ++++++- .../Repository/Connector/ConnectorTest.php | 2 +- .../Plugin/AbstractPluginTestCase.php | 2 +- .../Repository/WorkingCopyResolverTest.php | 2 +- 18 files changed, 81 insertions(+), 62 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11275f3..7639d22 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4' ] + php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] fail-fast: false name: Tests (PHP ${{ matrix.php }}) diff --git a/composer.json b/composer.json index 961f661..1429e3f 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,7 @@ ], "require": { "php": "^5.6|>=7.0.8", - "symfony/process": "^3.4", - "symfony/console": "^3.4", + "symfony/process": "^3.4 || ^4.0 || ^5.0", "console-helpers/console-kit": "^0.1@dev", "aura/sql": "^3.0 || ^4.0 || ^5.0", "padraic/phar-updater": "dev-use-curl", diff --git a/composer.lock b/composer.lock index 95dae2c..515347e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4727bbd666c5458f8c5a46c53cba3d2f", + "content-hash": "d4e137cbcbb06f918a3e26a071a48304", "packages": [ { "name": "aura/sql", diff --git a/src/SVNBuddy/Repository/CommitMessage/CommitMessageBuilder.php b/src/SVNBuddy/Repository/CommitMessage/CommitMessageBuilder.php index fed80f1..71e2286 100644 --- a/src/SVNBuddy/Repository/CommitMessage/CommitMessageBuilder.php +++ b/src/SVNBuddy/Repository/CommitMessage/CommitMessageBuilder.php @@ -46,7 +46,7 @@ public function build($wc_path, AbstractMergeTemplate $merge_template, $changeli { $commit_message_parts = array(); - if ( strlen($changelist) ) { + if ( !empty($changelist) ) { $commit_message_parts[] = trim($changelist); } diff --git a/src/SVNBuddy/Repository/Connector/Connector.php b/src/SVNBuddy/Repository/Connector/Connector.php index 0da8bbb..e116f6d 100644 --- a/src/SVNBuddy/Repository/Connector/Connector.php +++ b/src/SVNBuddy/Repository/Connector/Connector.php @@ -570,7 +570,7 @@ public function getWorkingCopyStatus( $status = $this->getCommand('status', array('--xml', $wc_path))->run(); - if ( !strlen($changelist) ) { + if ( empty($changelist) ) { // Accept all entries from "target" and "changelist" nodes. foreach ( $status->children() as $entries ) { $child_name = $entries->getName(); diff --git a/tests/SVNBuddy/AbstractTestCase.php b/tests/SVNBuddy/AbstractTestCase.php index e8c199a..1873c99 100644 --- a/tests/SVNBuddy/AbstractTestCase.php +++ b/tests/SVNBuddy/AbstractTestCase.php @@ -19,4 +19,21 @@ abstract class AbstractTestCase extends TestCase { use ProphecyTrait; + + /** + * Returns a test name. + * + * @return string + */ + protected function getTestName() + { + if ( method_exists($this, 'getName') ) { + // PHPUnit 9-. + return $this->getName(false); + } + + // PHPUnit 10+. + return $this->name(); + } + } diff --git a/tests/SVNBuddy/Config/AbstractConfigSettingTestCase.php b/tests/SVNBuddy/Config/AbstractConfigSettingTestCase.php index ad0b107..76d3124 100644 --- a/tests/SVNBuddy/Config/AbstractConfigSettingTestCase.php +++ b/tests/SVNBuddy/Config/AbstractConfigSettingTestCase.php @@ -294,7 +294,7 @@ public function testSetValueNormalization($value, $normalized_value) $this->assertSame($normalized_value, $config_setting->getValue()); } - public static function normalizationValueDataProvider($test_name, $value = null, $normalized_value = null) + public static function normalizationValueDataProvider() { throw new \RuntimeException('Override me.'); } @@ -334,7 +334,7 @@ public function testSetValueWithInheritanceFromDefault($wc_value, $global_value) $this->assertNull($this->configEditor->get('global-settings.name'), 'Inherited value isn\'t stored'); } - public static function setValueWithInheritanceDataProvider($test_name, $wc_value = null, $global_value = null) + public static function setValueWithInheritanceDataProvider() { throw new \RuntimeException('Override me.'); } @@ -350,7 +350,7 @@ public function testStorage($user_value, $stored_value) $this->assertSame($stored_value, $this->configEditor->get('global-settings.name')); } - public static function storageDataProvider($test_name, $default_value = null, $stored_value = null) + public static function storageDataProvider() { throw new \RuntimeException('Override me.'); } diff --git a/tests/SVNBuddy/Config/ArrayConfigSettingTest.php b/tests/SVNBuddy/Config/ArrayConfigSettingTest.php index 3c71bfe..9da277c 100644 --- a/tests/SVNBuddy/Config/ArrayConfigSettingTest.php +++ b/tests/SVNBuddy/Config/ArrayConfigSettingTest.php @@ -34,10 +34,10 @@ protected function setupTest() parent::setupTest(); } - public static function normalizationValueDataProvider($test_name, $value = array('a'), $normalized_value = array('b')) + public static function normalizationValueDataProvider() { - $value = static::getSampleValue($value, true); - $normalized_value = static::getSampleValue($normalized_value, true); + $value = static::getSampleValue(array('a'), true); + $normalized_value = static::getSampleValue(array('b'), true); return array( 'empty array' => array( @@ -75,10 +75,10 @@ public static function normalizationValueDataProvider($test_name, $value = array ); } - public static function setValueWithInheritanceDataProvider($test_name, $wc_value = array('global_value'), $global_value = array('default')) + public static function setValueWithInheritanceDataProvider() { - $wc_value = static::getSampleValue($wc_value); - $global_value = static::getSampleValue($global_value); + $wc_value = static::getSampleValue(array('global_value')); + $global_value = static::getSampleValue(array('default')); return array( array($wc_value, $global_value), @@ -95,10 +95,10 @@ public function testDefaultValueIsConvertedToScalar($default_value, $user_value) $this->assertSame($user_value, $config_setting->getValue(AbstractConfigSetting::SCOPE_GLOBAL)); } - public static function defaultValueIsConvertedToScalarDataProvider($test_name, $default_value = array('a'), $stored_value = array('b')) + public static function defaultValueIsConvertedToScalarDataProvider() { - $default_value = static::getSampleValue($default_value, true); - $stored_value = static::getSampleValue($stored_value, true); + $default_value = static::getSampleValue(array('a'), true); + $stored_value = static::getSampleValue(array('b'), true); return array( 'array into string' => array(array($default_value, $stored_value), array($default_value, $stored_value)), @@ -106,10 +106,10 @@ public static function defaultValueIsConvertedToScalarDataProvider($test_name, $ ); } - public static function storageDataProvider($test_name, $default_value = array('a'), $stored_value = array('b')) + public static function storageDataProvider() { - $default_value = static::getSampleValue($default_value, true); - $stored_value = static::getSampleValue($stored_value, true); + $default_value = static::getSampleValue(array('a'), true); + $stored_value = static::getSampleValue(array('b'), true); return array( 'array into string' => array(array($default_value, $stored_value), $default_value . PHP_EOL . $stored_value), diff --git a/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php b/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php index 1ce91b6..d222542 100644 --- a/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php +++ b/tests/SVNBuddy/Config/ChoiceConfigSettingTest.php @@ -34,10 +34,10 @@ protected function setupTest() parent::setupTest(); } - public static function normalizationValueDataProvider($test_name, $value = 1, $normalized_value = 1) + public static function normalizationValueDataProvider() { - $value = static::getSampleValue($value, true); - $normalized_value = static::getSampleValue($normalized_value, true); + $value = static::getSampleValue(1, true); + $normalized_value = static::getSampleValue(1, true); return array( 'as is' => array( @@ -56,20 +56,20 @@ public function testSetValueUnknownChoice() $config_setting->setValue(5); } - public static function setValueWithInheritanceDataProvider($test_name, $wc_value = 2, $global_value = 1) + public static function setValueWithInheritanceDataProvider() { - $wc_value = static::getSampleValue($wc_value, true); - $global_value = static::getSampleValue($global_value, true); + $wc_value = static::getSampleValue(2, true); + $global_value = static::getSampleValue(1, true); return array( array($wc_value, $global_value), ); } - public static function storageDataProvider($test_name, $default_value = 1, $stored_value = 1) + public static function storageDataProvider() { - $default_value = static::getSampleValue($default_value, true); - $stored_value = static::getSampleValue($stored_value, true); + $default_value = static::getSampleValue(1, true); + $stored_value = static::getSampleValue(1, true); return array( 'as is' => array($default_value, $stored_value), diff --git a/tests/SVNBuddy/Config/IntegerConfigSettingTest.php b/tests/SVNBuddy/Config/IntegerConfigSettingTest.php index 2d82953..3ed344f 100644 --- a/tests/SVNBuddy/Config/IntegerConfigSettingTest.php +++ b/tests/SVNBuddy/Config/IntegerConfigSettingTest.php @@ -34,10 +34,10 @@ protected function setupTest() parent::setupTest(); } - public static function normalizationValueDataProvider($test_name, $value = 1, $normalized_value = 0) + public static function normalizationValueDataProvider() { - $value = static::getSampleValue($value, true); - $normalized_value = static::getSampleValue($normalized_value, true); + $value = static::getSampleValue(1, true); + $normalized_value = static::getSampleValue(0, true); return array( 'integer' => array( @@ -91,20 +91,20 @@ public static function sampleArrayDataProvider() ); } - public static function setValueWithInheritanceDataProvider($test_name, $wc_value = 2, $global_value = 1) + public static function setValueWithInheritanceDataProvider() { - $wc_value = static::getSampleValue($wc_value, true); - $global_value = static::getSampleValue($global_value, true); + $wc_value = static::getSampleValue(2, true); + $global_value = static::getSampleValue(1, true); return array( array($wc_value, $global_value), ); } - public static function storageDataProvider($test_name, $default_value = 1, $stored_value = 1) + public static function storageDataProvider() { - $default_value = static::getSampleValue($default_value, true); - $stored_value = static::getSampleValue($stored_value, true); + $default_value = static::getSampleValue(1, true); + $stored_value = static::getSampleValue(1, true); return array( 'integer' => array($default_value, $default_value), diff --git a/tests/SVNBuddy/Config/StringConfigSettingTest.php b/tests/SVNBuddy/Config/StringConfigSettingTest.php index 1460b52..b58e910 100644 --- a/tests/SVNBuddy/Config/StringConfigSettingTest.php +++ b/tests/SVNBuddy/Config/StringConfigSettingTest.php @@ -34,10 +34,10 @@ protected function setupTest() parent::setupTest(); } - public static function normalizationValueDataProvider($test_name, $value = 'a', $normalized_value = 'b') + public static function normalizationValueDataProvider() { - $value = static::getSampleValue($value, true); - $normalized_value = static::getSampleValue($normalized_value, true); + $value = static::getSampleValue('a', true); + $normalized_value = static::getSampleValue('b', true); return array( 'empty string' => array( @@ -83,20 +83,20 @@ public static function sampleArrayDataProvider() ); } - public static function setValueWithInheritanceDataProvider($test_name, $wc_value = 'global_value', $global_value = 'default') + public static function setValueWithInheritanceDataProvider() { - $wc_value = static::getSampleValue($wc_value, true); - $global_value = static::getSampleValue($global_value, true); + $wc_value = static::getSampleValue('global_value', true); + $global_value = static::getSampleValue('default', true); return array( array($wc_value, $global_value), ); } - public static function storageDataProvider($test_name, $default_value = 'a', $stored_value = 'b') + public static function storageDataProvider() { - $default_value = static::getSampleValue($default_value, true); - $stored_value = static::getSampleValue($stored_value, true); + $default_value = static::getSampleValue('a', true); + $stored_value = static::getSampleValue('b', true); return array( 'string' => array($default_value, $default_value), diff --git a/tests/SVNBuddy/Database/AbstractDatabaseAwareTestCase.php b/tests/SVNBuddy/Database/AbstractDatabaseAwareTestCase.php index 44d8ec7..5f9a669 100644 --- a/tests/SVNBuddy/Database/AbstractDatabaseAwareTestCase.php +++ b/tests/SVNBuddy/Database/AbstractDatabaseAwareTestCase.php @@ -72,7 +72,8 @@ protected function assertTableEmpty($table_name) */ protected function assertTableContent($table_name, array $expected_content) { - $this->assertSame( + // Can't use "assertSame", because on PHP 8+ the PDO casts the data (e.g. '1' becomes 1). + $this->assertEquals( $expected_content, $this->_dumpTable($table_name), 'Table "' . $table_name . '" content isn\'t correct.' diff --git a/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php b/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php index 75dddd0..4d70fa5 100644 --- a/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php +++ b/tests/SVNBuddy/MergeSourceDetector/MergeSourceDetectorAggregatorTest.php @@ -31,6 +31,10 @@ class MergeSourceDetectorAggregatorTest extends AbstractMergeSourceDetectorTestC */ protected function setupTest() { + if ( $this->getTestName() === 'testDetect' ) { + $this->markTestSkipped('Cross-detector matching tests done separately'); + } + $sub_detector1 = $this->prophesize(AbstractMergeSourceDetector::class); $sub_detector1->getWeight()->willReturn(2)->shouldBeCalled(); $this->detectors[] = $sub_detector1; @@ -44,14 +48,6 @@ protected function setupTest() $this->detectors[] = $sub_detector2; } - /** - * @dataProvider repositoryUrlDataProvider - */ - public function testDetect($repository_url, $result) - { - $this->markTestSkipped('Cross-detector matching tests done separately'); - } - public function testNoMatchFound() { $detector = $this->createDetector(); diff --git a/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php b/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php index 80beabe..03a7c7f 100644 --- a/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php +++ b/tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php @@ -169,7 +169,7 @@ private function _expectCommand(array $command, $output, $error_msg = null, $err ); } else { - $expectation->willReturn(null); + $expectation->willReturn($process); $process->getOutput()->willReturn($output)->shouldBeCalled(); } diff --git a/tests/SVNBuddy/Repository/Connector/CommandTest.php b/tests/SVNBuddy/Repository/Connector/CommandTest.php index a8f80c5..751d8a2 100644 --- a/tests/SVNBuddy/Repository/Connector/CommandTest.php +++ b/tests/SVNBuddy/Repository/Connector/CommandTest.php @@ -98,6 +98,8 @@ public function testRunWithoutCaching($use_callback, $is_xml) if ( is_callable($args[0]) ) { call_user_func($args[0], Process::OUT, $process_output); } + + return $this; }) ->shouldBeCalled(); @@ -259,6 +261,8 @@ protected function configureProcess($callback, $process_output, $will_run) if ( is_callable($args[0]) ) { call_user_func($args[0], Process::OUT, $process_output); } + + return $this; }) ->shouldBeCalled(); @@ -387,7 +391,9 @@ public function testRunLive($output_type, $expected_output) $this->_process ->mustRun(Argument::type('callable')) ->will(function (array $args) use ($output_type) { - return call_user_func($args[0], $output_type, "TEX\nT"); + call_user_func($args[0], $output_type, "TEX\nT"); + + return $this; }) ->shouldBeCalled(); $this->_process->getOutput()->willReturn('OK')->shouldBeCalled(); diff --git a/tests/SVNBuddy/Repository/Connector/ConnectorTest.php b/tests/SVNBuddy/Repository/Connector/ConnectorTest.php index 2734c9d..73428c0 100644 --- a/tests/SVNBuddy/Repository/Connector/ConnectorTest.php +++ b/tests/SVNBuddy/Repository/Connector/ConnectorTest.php @@ -196,7 +196,7 @@ public function testGetWorkingCopyUrlFromPath($raw_command_output, $path, $url) $this->assertEquals($url, $actual); } - public function svnInfoDataProvider() + public static function svnInfoDataProvider() { return array( 'svn1.6_wc_root_with_peg' => array(self::getFixture('svn_info_peg_16.xml'), '/path/to/working-c@py', self::DUMMY_REPO), diff --git a/tests/SVNBuddy/Repository/RevisionLog/Plugin/AbstractPluginTestCase.php b/tests/SVNBuddy/Repository/RevisionLog/Plugin/AbstractPluginTestCase.php index f943b9a..d3b0e7e 100644 --- a/tests/SVNBuddy/Repository/RevisionLog/Plugin/AbstractPluginTestCase.php +++ b/tests/SVNBuddy/Repository/RevisionLog/Plugin/AbstractPluginTestCase.php @@ -49,7 +49,7 @@ protected function setupTest() { parent::setupTest(); - if ( strpos($this->getName(false), 'testProcess') === 0 ) { + if ( strpos($this->getTestName(), 'testProcess') === 0 ) { $this->database->setProfiler($this->createStatementProfiler()); } diff --git a/tests/SVNBuddy/Repository/WorkingCopyResolverTest.php b/tests/SVNBuddy/Repository/WorkingCopyResolverTest.php index 262156e..a865eeb 100644 --- a/tests/SVNBuddy/Repository/WorkingCopyResolverTest.php +++ b/tests/SVNBuddy/Repository/WorkingCopyResolverTest.php @@ -55,7 +55,7 @@ protected function setupTest() */ protected function teardownTest() { - if ( strlen($this->tempFolder) && file_exists($this->tempFolder) ) { + if ( !empty($this->tempFolder) && file_exists($this->tempFolder) ) { rmdir($this->tempFolder); } }