Skip to content

Commit c94011b

Browse files
authored
Merge pull request #225 from aik099/phpunit10-compat
PHPUnit 10 compatibility
2 parents 7105a5e + 4ca8034 commit c94011b

File tree

12 files changed

+190
-85
lines changed

12 files changed

+190
-85
lines changed

.github/workflows/tests.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,27 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
php: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
23+
include:
24+
- php: '5.6'
25+
phpunit_config: 'phpunit.xml.dist' # PHPUnit 5.7
26+
- php: '7.0'
27+
phpunit_config: 'phpunit.xml.dist' # PHPUnit 6.5
28+
- php: '7.1'
29+
phpunit_config: 'phpunit7.xml.dist' # PHPUnit 7.5
30+
- php: '7.2'
31+
phpunit_config: 'phpunit7.xml.dist' # PHPUnit 8.5
32+
- php: '7.3'
33+
phpunit_config: 'phpunit9.xml.dist' # PHPUnit 9.6
34+
- php: '7.4'
35+
phpunit_config: 'phpunit9.xml.dist' # PHPUnit 9.6
36+
- php: '8.0'
37+
phpunit_config: 'phpunit9.xml.dist' # PHPUnit 9.6
38+
- php: '8.1'
39+
phpunit_config: 'phpunit10.xml.dist' # PHPUnit 10.5
40+
- php: '8.2'
41+
phpunit_config: 'phpunit10.xml.dist' # PHPUnit 10.5
42+
- php: '8.3'
43+
phpunit_config: 'phpunit10.xml.dist' # PHPUnit 10.5
2444
fail-fast: false
2545
env:
2646
REPO_URL: http://localhost:8002/
@@ -60,7 +80,7 @@ jobs:
6080
6181
- name: Run tests
6282
run: |
63-
vendor/bin/phpunit --log-junit junit.xml --coverage-clover clover.xml
83+
vendor/bin/phpunit --configuration ${{ matrix.phpunit_config }} --log-junit junit.xml --coverage-clover clover.xml
6484
6585
- name: Upload coverage to Codecov
6686
uses: codecov/codecov-action@v5

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"require-dev": {
1818
"aik099/coding-standard": "dev-master",
1919
"squizlabs/php_codesniffer": "^2.6",
20-
"yoast/phpunit-polyfills": "^1.0",
20+
"yoast/phpunit-polyfills": "^2.0",
2121
"phpspec/prophecy": "^1.10",
2222
"console-helpers/prophecy-phpunit": "^3.0"
2323
},

composer.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="true"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnError="false"
11-
stopOnFailure="false"
12-
stopOnIncomplete="false"
13-
stopOnSkipped="false"
14-
syntaxCheck="true"
15-
strict="true"
16-
verbose="true">
3+
backupGlobals="true"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutOutputDuringTests="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true"
9+
verbose="true">
1710

18-
<testsuites>
19-
<testsuite name="Jira_Api Test Suite">
20-
<directory>tests</directory>
21-
</testsuite>
22-
</testsuites>
11+
<testsuites>
12+
<testsuite name="Jira_Api Test Suite">
13+
<directory>tests</directory>
14+
</testsuite>
15+
</testsuites>
2316

2417
<filter>
2518
<whitelist>
2619
<directory>src</directory>
2720
</whitelist>
2821
</filter>
2922

30-
<!--
31-
<php>
32-
<server name="REPO_URL" value="http://localhost/"/>
33-
</php>
34-
-->
35-
23+
<!--
24+
<php>
25+
<server name="REPO_URL" value="http://localhost/"/>
26+
</php>
27+
-->
3628
</phpunit>

phpunit10.xml.dist

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
3+
bootstrap="vendor/autoload.php"
4+
backupGlobals="true"
5+
backupStaticProperties="false"
6+
colors="true"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
8+
beStrictAboutOutputDuringTests="true"
9+
displayDetailsOnTestsThatTriggerDeprecations="true">
10+
11+
<testsuites>
12+
<testsuite name="Jira_Api Test Suite">
13+
<directory>tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
17+
<coverage>
18+
<include>
19+
<directory>src</directory>
20+
</include>
21+
</coverage>
22+
23+
<!--
24+
<php>
25+
<server name="REPO_URL" value="http://localhost/"/>
26+
</php>
27+
-->
28+
</phpunit>

phpunit7.xml.dist

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="true"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutOutputDuringTests="true"
8+
verbose="true">
9+
10+
<testsuites>
11+
<testsuite name="Jira_Api Test Suite">
12+
<directory>tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<filter>
17+
<whitelist>
18+
<directory>src</directory>
19+
</whitelist>
20+
</filter>
21+
22+
<!--
23+
<php>
24+
<server name="REPO_URL" value="http://localhost/"/>
25+
</php>
26+
-->
27+
</phpunit>

phpunit9.xml.dist

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
3+
bootstrap="vendor/autoload.php"
4+
backupGlobals="true"
5+
backupStaticAttributes="false"
6+
colors="true"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
8+
beStrictAboutOutputDuringTests="true"
9+
verbose="true">
10+
11+
<testsuites>
12+
<testsuite name="Jira_Api Test Suite">
13+
<directory>tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
17+
<coverage>
18+
<include>
19+
<directory>src</directory>
20+
</include>
21+
</coverage>
22+
23+
<!--
24+
<php>
25+
<server name="REPO_URL" value="http://localhost/"/>
26+
</php>
27+
-->
28+
</phpunit>

tests/Jira/AbstractTestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,21 @@ abstract class AbstractTestCase extends TestCase
1010
{
1111

1212
use ProphecyTrait;
13+
14+
/**
15+
* Returns a test name.
16+
*
17+
* @return string
18+
*/
19+
protected function getTestName()
20+
{
21+
if ( method_exists($this, 'getName') ) {
22+
// PHPUnit 9-.
23+
return $this->getName(false);
24+
}
25+
26+
// PHPUnit 10+.
27+
return $this->name();
28+
}
29+
1330
}

tests/Jira/Api/Client/AbstractClientTestCase.php

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
use chobie\Jira\Api\Authentication\AuthenticationInterface;
99
use chobie\Jira\Api\Authentication\Basic;
1010
use chobie\Jira\Api\Client\ClientInterface;
11+
use InvalidArgumentException;
1112
use Tests\chobie\Jira\AbstractTestCase;
12-
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
13+
use chobie\Jira\Api\UnauthorizedException;
14+
use chobie\Jira\Api\Exception;
1315

1416
abstract class AbstractClientTestCase extends AbstractTestCase
1517
{
1618

17-
use ExpectException;
18-
1919
/**
2020
* Client.
2121
*
@@ -48,7 +48,7 @@ public function testGetRequestWithKnownHttpCode($http_code)
4848
$this->assertEquals($data, $trace_result['_GET']);
4949
}
5050

51-
public function getRequestWithKnownHttpCodeDataProvider()
51+
public static function getRequestWithKnownHttpCodeDataProvider()
5252
{
5353
return array(
5454
'http 200' => array(200),
@@ -58,7 +58,7 @@ public function getRequestWithKnownHttpCodeDataProvider()
5858

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

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

139-
public function fileUploadDataProvider()
139+
public static function fileUploadDataProvider()
140140
{
141141
return array(
142-
'default name' => array('file' => __FILE__, 'name' => null),
143-
'overridden name' => array('file' => __FILE__, 'name' => 'custom_name.php'),
142+
'default name' => array('filename' => __FILE__, 'name' => null),
143+
'overridden name' => array('filename' => __FILE__, 'name' => 'custom_name.php'),
144144
);
145145
}
146146

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

152-
if ( \method_exists($this, 'setExpectedException') ) {
153-
$this->setExpectedException(
154-
'InvalidArgumentException',
155-
end($client_class_parts) . ' does not support ' . get_class($credential) . ' authentication.'
156-
);
157-
}
158-
else {
159-
$this->expectException('InvalidArgumentException');
160-
$this->expectExceptionMessage(
161-
end($client_class_parts) . ' does not support ' . get_class($credential) . ' authentication.'
162-
);
163-
}
152+
$this->expectException('InvalidArgumentException');
153+
$this->expectExceptionMessage(
154+
end($client_class_parts) . ' does not support ' . get_class($credential) . ' authentication.'
155+
);
164156

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

186178
public function testUnauthorizedRequest()
187179
{
188-
$this->expectException('\chobie\Jira\Api\UnauthorizedException');
180+
$this->expectException(UnauthorizedException::class);
189181
$this->expectExceptionMessage('Unauthorized');
190182

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

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

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

213-
public function emptyResponseWithKnownHttpCodeDataProvider()
205+
public static function emptyResponseWithKnownHttpCodeDataProvider()
214206
{
215207
return array(
216208
'http 201' => array(201),
@@ -246,10 +238,10 @@ protected function assertContentType($expected, array $trace_result)
246238
/**
247239
* Traces a request.
248240
*
249-
* @param string $method Request method.
250-
* @param array $data Request data.
251-
* @param AuthenticationInterface|null $credential Credential.
252-
* @param boolean $is_file This is a file upload request.
241+
* @param string $method Request method.
242+
* @param array $data Request data.
243+
* @param AuthenticationInterface|null $credential Credential.
244+
* @param boolean $is_file This is a file upload request.
253245
*
254246
* @return array
255247
*/

0 commit comments

Comments
 (0)