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

PHPUnit 10 support + testing on PHP 8+ #144

Merged
merged 1 commit into from
Mar 31, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,35 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4' ]
include:
- php: '5.6'
phpunit_config: 'phpunit.xml.dist' # PHPUnit 5.7
- php: '7.0'
phpunit_config: 'phpunit.xml.dist' # PHPUnit 6.5
- php: '7.1'
phpunit_config: 'phpunit7.xml.dist' # PHPUnit 7.5
- php: '7.2'
phpunit_config: 'phpunit7.xml.dist' # PHPUnit 8.5
- php: '7.3'
phpunit_config: 'phpunit9.xml.dist' # PHPUnit 9.6
- php: '7.4'
phpunit_config: 'phpunit9.xml.dist' # PHPUnit 9.6
- php: '8.0'
phpunit_config: 'phpunit9.xml.dist' # PHPUnit 9.6
- php: '8.1'
phpunit_config: 'phpunit10.xml.dist' # PHPUnit 10.5
- php: '8.2'
phpunit_config: 'phpunit10.xml.dist' # PHPUnit 10.5
- php: '8.3'
phpunit_config: 'phpunit10.xml.dist' # PHPUnit 10.5
fail-fast: false

name: Tests (PHP ${{ matrix.php }})
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -39,14 +61,19 @@ jobs:
LINES: 30
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-clover build/logs/clover.xml

- name: Downloading Scrutinizer CI binary
run: wget https://scrutinizer-ci.com/ocular.phar
vendor/bin/phpunit --configuration ${{ matrix.phpunit_config }} --coverage-clover=coverage.clover

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

- name: Uploading code coverage to Scrutinizer CI
run: php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
- name: Upload Coverage to Scrutinizer CI (PHP < 8.0)
if: "${{ matrix.php < '8.0' }}"
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --repository=g/console-helpers/svn-buddy --format=php-clover coverage.clover

- name: Upload Coverage to Scrutinizer CI (PHP >= 8.0)
if: "${{ matrix.php >= '8.0' }}"
run: |
composer require scrutinizer/ocular
vendor/bin/ocular code-coverage:upload --repository=g/console-helpers/svn-buddy --format=php-clover coverage.clover
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
verbose="true">

<testsuites>
Expand Down
30 changes: 30 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true">

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<!--<logging>
<log type="coverage-html" target="build/coverage" title="BankAccount"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
</logging>-->

<php>
<server name="working_directory" value=".svn-buddy"/>
</php>

<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
29 changes: 29 additions & 0 deletions phpunit7.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
verbose="true">

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<!--<logging>
<log type="coverage-html" target="build/coverage" title="BankAccount"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
</logging>-->

<php>
<server name="working_directory" value=".svn-buddy"/>
</php>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
30 changes: 30 additions & 0 deletions phpunit9.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
verbose="true">

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<!--<logging>
<log type="coverage-html" target="build/coverage" title="BankAccount"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
</logging>-->

<php>
<server name="working_directory" value=".svn-buddy"/>
</php>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
</phpunit>
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();
}

}
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
20 changes: 15 additions & 5 deletions tests/SVNBuddy/Database/StatementProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,18 @@ public function testVerboseOutput()
$io = $this->prophesize('ConsoleHelpers\ConsoleKit\ConsoleIO');
$io->isVerbose()->willReturn(true)->shouldBeCalled();

// The PHP7 threats multi-line statement position differently in traces.
$expect_line = PHP_VERSION_ID < 70000 ? 236 : 235;
if ( PHP_VERSION_ID >= 80200 ) {
// Adjust for PHP 8.2+ multi-line statement handling in traces.
$expect_line = 241;
}
elseif ( PHP_VERSION_ID >= 70000 ) {
// Adjust for PHP 7.0+ multi-line statement handling in traces.
$expect_line = 245;
}
else {
// Adjust for PHP 5.0+ multi-line statement handling in traces.
$expect_line = 246;
}

$io
->writeln(array(
Expand All @@ -228,12 +238,12 @@ public function testVerboseOutput()
$this->statementProfiler->setIO($io->reveal());

$this->statementProfiler->setActive(true);
$this->statementProfiler->addProfile(
$this->statementProfiler->addProfile( // 241
5,
'perform',
'SELECT :pa :param',
array('pa' => 'PA', 'param' => array('PAR', 'AM'))
);
array('pa' => 'PA', 'param' => array('PAR', 'AM')) // 245
); // 246
$this->assertCount(1, $this->statementProfiler->getProfiles());
}

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
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
Loading