Skip to content

Commit

Permalink
Merge pull request #225 from aik099/phpunit10-compat
Browse files Browse the repository at this point in the history
PHPUnit 10 compatibility
  • Loading branch information
aik099 authored Jan 2, 2025
2 parents 7105a5e + 4ca8034 commit c94011b
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 85 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,27 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
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
env:
REPO_URL: http://localhost:8002/
Expand Down Expand Up @@ -60,7 +80,7 @@ jobs:
- name: Run tests
run: |
vendor/bin/phpunit --log-junit junit.xml --coverage-clover clover.xml
vendor/bin/phpunit --configuration ${{ matrix.phpunit_config }} --log-junit junit.xml --coverage-clover clover.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require-dev": {
"aik099/coding-standard": "dev-master",
"squizlabs/php_codesniffer": "^2.6",
"yoast/phpunit-polyfills": "^1.0",
"yoast/phpunit-polyfills": "^2.0",
"phpspec/prophecy": "^1.10",
"console-helpers/prophecy-phpunit": "^3.0"
},
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

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

42 changes: 17 additions & 25 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
syntaxCheck="true"
strict="true"
verbose="true">
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
verbose="true">

<testsuites>
<testsuite name="Jira_Api Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Jira_Api Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
</php>
-->

<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
</php>
-->
</phpunit>
28 changes: 28 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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="vendor/autoload.php"
backupGlobals="true"
backupStaticProperties="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true">

<testsuites>
<testsuite name="Jira_Api Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>

<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
</php>
-->
</phpunit>
27 changes: 27 additions & 0 deletions phpunit7.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
verbose="true">

<testsuites>
<testsuite name="Jira_Api Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
</php>
-->
</phpunit>
28 changes: 28 additions & 0 deletions phpunit9.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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="vendor/autoload.php"
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
verbose="true">

<testsuites>
<testsuite name="Jira_Api Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>

<!--
<php>
<server name="REPO_URL" value="http://localhost/"/>
</php>
-->
</phpunit>
17 changes: 17 additions & 0 deletions tests/Jira/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,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();
}

}
48 changes: 20 additions & 28 deletions tests/Jira/Api/Client/AbstractClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use chobie\Jira\Api\Authentication\AuthenticationInterface;
use chobie\Jira\Api\Authentication\Basic;
use chobie\Jira\Api\Client\ClientInterface;
use InvalidArgumentException;
use Tests\chobie\Jira\AbstractTestCase;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use chobie\Jira\Api\UnauthorizedException;
use chobie\Jira\Api\Exception;

abstract class AbstractClientTestCase extends AbstractTestCase
{

use ExpectException;

/**
* Client.
*
Expand Down Expand Up @@ -48,7 +48,7 @@ public function testGetRequestWithKnownHttpCode($http_code)
$this->assertEquals($data, $trace_result['_GET']);
}

public function getRequestWithKnownHttpCodeDataProvider()
public static function getRequestWithKnownHttpCodeDataProvider()
{
return array(
'http 200' => array(200),
Expand All @@ -58,7 +58,7 @@ public function getRequestWithKnownHttpCodeDataProvider()

public function testGetRequestError()
{
$this->expectException('\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Data must be an array.');

$this->traceRequest(Api::REQUEST_GET, 'param1=value1&param2=value2');
Expand Down Expand Up @@ -136,31 +136,23 @@ public function testFileUpload($filename, $name)
);
}

public function fileUploadDataProvider()
public static function fileUploadDataProvider()
{
return array(
'default name' => array('file' => __FILE__, 'name' => null),
'overridden name' => array('file' => __FILE__, 'name' => 'custom_name.php'),
'default name' => array('filename' => __FILE__, 'name' => null),
'overridden name' => array('filename' => __FILE__, 'name' => 'custom_name.php'),
);
}

public function testUnsupportedCredentialGiven()
{
$client_class_parts = explode('\\', get_class($this->client));
$credential = $this->prophesize('chobie\Jira\Api\Authentication\AuthenticationInterface')->reveal();
$credential = $this->prophesize(AuthenticationInterface::class)->reveal();

if ( \method_exists($this, 'setExpectedException') ) {
$this->setExpectedException(
'InvalidArgumentException',
end($client_class_parts) . ' does not support ' . get_class($credential) . ' authentication.'
);
}
else {
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage(
end($client_class_parts) . ' does not support ' . get_class($credential) . ' authentication.'
);
}
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage(
end($client_class_parts) . ' does not support ' . get_class($credential) . ' authentication.'
);

$this->client->sendRequest(Api::REQUEST_GET, 'url', array(), 'endpoint', $credential);
}
Expand All @@ -185,15 +177,15 @@ public function testCommunicationError()

public function testUnauthorizedRequest()
{
$this->expectException('\chobie\Jira\Api\UnauthorizedException');
$this->expectException(UnauthorizedException::class);
$this->expectExceptionMessage('Unauthorized');

$this->traceRequest(Api::REQUEST_GET, array('http_code' => 401));
}

public function testEmptyResponseWithUnknownHttpCode()
{
$this->expectException('\chobie\Jira\Api\Exception');
$this->expectException(Exception::class);
$this->expectExceptionMessage('JIRA Rest server returns unexpected result.');

$this->traceRequest(Api::REQUEST_GET, array('response_mode' => 'empty'));
Expand All @@ -210,7 +202,7 @@ public function testEmptyResponseWithKnownHttpCode($http_code)
);
}

public function emptyResponseWithKnownHttpCodeDataProvider()
public static function emptyResponseWithKnownHttpCodeDataProvider()
{
return array(
'http 201' => array(201),
Expand Down Expand Up @@ -246,10 +238,10 @@ protected function assertContentType($expected, array $trace_result)
/**
* Traces a request.
*
* @param string $method Request method.
* @param array $data Request data.
* @param AuthenticationInterface|null $credential Credential.
* @param boolean $is_file This is a file upload request.
* @param string $method Request method.
* @param array $data Request data.
* @param AuthenticationInterface|null $credential Credential.
* @param boolean $is_file This is a file upload request.
*
* @return array
*/
Expand Down
Loading

0 comments on commit c94011b

Please sign in to comment.