Skip to content

Commit

Permalink
PHPUnit 10 support + testing on PHP 8+
Browse files Browse the repository at this point in the history
Lift restriction on used "symfony/process" component version

Correct "symfony/process"-related tests
  • Loading branch information
aik099 committed Mar 30, 2024
1 parent 5776998 commit 8bc47ee
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/SVNBuddy/Repository/Connector/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions tests/SVNBuddy/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
6 changes: 3 additions & 3 deletions tests/SVNBuddy/Config/AbstractConfigSettingTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down Expand Up @@ -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.');
}
Expand All @@ -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.');
}
Expand Down
24 changes: 12 additions & 12 deletions tests/SVNBuddy/Config/ArrayConfigSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -95,21 +95,21 @@ 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)),
'array as string' => array($default_value . PHP_EOL . $stored_value, array($default_value, $stored_value)),
);
}

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),
Expand Down
18 changes: 9 additions & 9 deletions tests/SVNBuddy/Config/ChoiceConfigSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions tests/SVNBuddy/Config/IntegerConfigSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions tests/SVNBuddy/Config/StringConfigSettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion tests/SVNBuddy/Database/AbstractDatabaseAwareTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/SVNBuddy/Repository/Connector/CommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
8 changes: 7 additions & 1 deletion tests/SVNBuddy/Repository/Connector/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/SVNBuddy/Repository/Connector/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/SVNBuddy/Repository/WorkingCopyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 8bc47ee

Please sign in to comment.