diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ff64ef9..49a3b13 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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/ @@ -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 diff --git a/composer.json b/composer.json index af8b85d..33cf7c4 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/composer.lock b/composer.lock index 4c0c5f0..9931fa5 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": "e1f2814f071d8659049fdfc965cbf456", + "content-hash": "06003a891d216c9dfe128a957ebbf075", "packages": [], "packages-dev": [ { @@ -1551,12 +1551,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + }, "branch-alias": { "dev-main": "1.19-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -1734,21 +1734,21 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "1.1.2", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "e9c8413de4c8ae03d2923a44f17d0d7dad1b96be" + "reference": "562f449a2ec8ab92fe7b30d94da9622c7b1345fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/e9c8413de4c8ae03d2923a44f17d0d7dad1b96be", - "reference": "e9c8413de4c8ae03d2923a44f17d0d7dad1b96be", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/562f449a2ec8ab92fe7b30d94da9622c7b1345fe", + "reference": "562f449a2ec8ab92fe7b30d94da9622c7b1345fe", "shasum": "" }, "require": { - "php": ">=5.4", - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "php": ">=5.6", + "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0.0", @@ -1793,7 +1793,7 @@ "security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2024-09-06T22:03:10+00:00" + "time": "2024-09-06T22:38:28+00:00" } ], "aliases": [], diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 166e531..18483cf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,18 @@ + backupGlobals="true" + backupStaticAttributes="false" + colors="true" + beStrictAboutTestsThatDoNotTestAnything="true" + beStrictAboutOutputDuringTests="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + verbose="true"> - - - tests - - + + + tests + + @@ -27,10 +20,9 @@ - - + diff --git a/phpunit10.xml.dist b/phpunit10.xml.dist new file mode 100644 index 0000000..23e03cf --- /dev/null +++ b/phpunit10.xml.dist @@ -0,0 +1,28 @@ + + + + + + tests + + + + + + src + + + + + diff --git a/phpunit7.xml.dist b/phpunit7.xml.dist new file mode 100644 index 0000000..d958cd7 --- /dev/null +++ b/phpunit7.xml.dist @@ -0,0 +1,27 @@ + + + + + + tests + + + + + + src + + + + + diff --git a/phpunit9.xml.dist b/phpunit9.xml.dist new file mode 100644 index 0000000..9d4781d --- /dev/null +++ b/phpunit9.xml.dist @@ -0,0 +1,28 @@ + + + + + + tests + + + + + + src + + + + + diff --git a/tests/Jira/AbstractTestCase.php b/tests/Jira/AbstractTestCase.php index 13091fb..96ab9a2 100644 --- a/tests/Jira/AbstractTestCase.php +++ b/tests/Jira/AbstractTestCase.php @@ -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(); + } + } diff --git a/tests/Jira/Api/Client/AbstractClientTestCase.php b/tests/Jira/Api/Client/AbstractClientTestCase.php index fb8bc07..c74c2f9 100644 --- a/tests/Jira/Api/Client/AbstractClientTestCase.php +++ b/tests/Jira/Api/Client/AbstractClientTestCase.php @@ -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. * @@ -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), @@ -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¶m2=value2'); @@ -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); } @@ -185,7 +177,7 @@ 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)); @@ -193,7 +185,7 @@ public function testUnauthorizedRequest() 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')); @@ -210,7 +202,7 @@ public function testEmptyResponseWithKnownHttpCode($http_code) ); } - public function emptyResponseWithKnownHttpCodeDataProvider() + public static function emptyResponseWithKnownHttpCodeDataProvider() { return array( 'http 201' => array(201), @@ -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 */ diff --git a/tests/Jira/ApiTest.php b/tests/Jira/ApiTest.php index fb8fea1..51ac969 100644 --- a/tests/Jira/ApiTest.php +++ b/tests/Jira/ApiTest.php @@ -8,6 +8,7 @@ use chobie\Jira\Api\Result; use chobie\Jira\IssueType; use Prophecy\Prophecy\ObjectProphecy; +use chobie\Jira\Api\Client\ClientInterface; /** * Class ApiTest @@ -45,8 +46,8 @@ class ApiTest extends AbstractTestCase */ protected function setUpTest() { - $this->credential = $this->prophesize('chobie\Jira\Api\Authentication\AuthenticationInterface')->reveal(); - $this->client = $this->prophesize('chobie\Jira\Api\Client\ClientInterface'); + $this->credential = $this->prophesize(AuthenticationInterface::class)->reveal(); + $this->client = $this->prophesize(ClientInterface::class); $this->api = new Api(self::ENDPOINT, $this->credential, $this->client->reveal()); } @@ -60,7 +61,7 @@ public function testSetEndpoint($given_endpoint, $used_endpoint) $this->assertEquals($used_endpoint, $api->getEndpoint()); } - public function setEndpointDataProvider() + public static function setEndpointDataProvider() { return array( 'trailing slash removed' => array('https://test.test/', 'https://test.test'), diff --git a/tests/Jira/IssueTypeTest.php b/tests/Jira/IssueTypeTest.php index 260851d..b3dc4e4 100644 --- a/tests/Jira/IssueTypeTest.php +++ b/tests/Jira/IssueTypeTest.php @@ -4,11 +4,10 @@ use chobie\Jira\IssueType; -use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use Exception; class IssueTypeTest extends AbstractTestCase { - use ExpectException; public function testHandlesSingleIssueTypeWithAvatarId() { @@ -66,14 +65,14 @@ public function testGettingUnknownProperty() ); $issue_type = new IssueType($issue_type_source); - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('The "chobie\Jira\IssueType::getUnknown" method does not exist.'); $issue_type->getUnknown(); } public function testCreatingWithUnknownField() { - $this->expectException(\Exception::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('The "unknown" issue type keys are not supported.'); $issue_type_source = array( diff --git a/tests/Jira/Issues/WalkerTest.php b/tests/Jira/Issues/WalkerTest.php index 670c049..260bc67 100644 --- a/tests/Jira/Issues/WalkerTest.php +++ b/tests/Jira/Issues/WalkerTest.php @@ -7,15 +7,16 @@ use chobie\Jira\Api\UnauthorizedException; use chobie\Jira\Issue; use chobie\Jira\Issues\Walker; +use Exception; use Prophecy\Prophecy\ObjectProphecy; use Tests\chobie\Jira\AbstractTestCase; use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; -use Yoast\PHPUnitPolyfills\Polyfills\ExpectException; +use chobie\Jira\Api; class WalkerTest extends AbstractTestCase { - use ExpectException, AssertStringContains; + use AssertStringContains; /** * API. @@ -36,7 +37,7 @@ class WalkerTest extends AbstractTestCase */ protected function setUpTest() { - $this->api = $this->prophesize('chobie\Jira\Api'); + $this->api = $this->prophesize(Api::class); if ( $this->captureErrorLog() ) { $this->errorLogFile = tempnam(sys_get_temp_dir(), 'error_log_'); @@ -64,12 +65,12 @@ protected function tearDownTest() */ protected function captureErrorLog() { - return strpos($this->getName(false), 'AnyException') !== false; + return strpos($this->getTestName(), 'AnyException') !== false; } public function testErrorWithoutJQL() { - $this->expectException('\Exception'); + $this->expectException(Exception::class); $this->expectExceptionMessage('you have to call Jira_Walker::push($jql, $fields) at first'); foreach ( $this->createWalker() as $issue ) { @@ -141,7 +142,7 @@ public function testFoundTwoPagesOfIssues() public function testUnauthorizedExceptionOnFirstPage() { - $this->expectException('\chobie\Jira\Api\UnauthorizedException'); + $this->expectException(UnauthorizedException::class); $this->expectExceptionMessage('Unauthorized'); $this->api->search('test jql', 0, 5, 'description')->willThrow(new UnauthorizedException('Unauthorized')); @@ -156,7 +157,7 @@ public function testUnauthorizedExceptionOnFirstPage() public function testAnyExceptionOnFirstPage() { - $this->api->search('test jql', 0, 5, 'description')->willThrow(new \Exception('Anything')); + $this->api->search('test jql', 0, 5, 'description')->willThrow(new Exception('Anything')); $walker = $this->createWalker(5); $walker->push('test jql', 'description'); @@ -170,7 +171,7 @@ public function testAnyExceptionOnFirstPage() public function testUnauthorizedExceptionOnSecondPage() { - $this->expectException('\chobie\Jira\Api\UnauthorizedException'); + $this->expectException(UnauthorizedException::class); $this->expectExceptionMessage('Unauthorized'); // Full 1st page. @@ -195,7 +196,7 @@ public function testAnyExceptionOnSecondPage() $this->api->search('test jql', 0, 5, 'description')->willReturn($search_response1); // Incomplete 2nd page. - $this->api->search('test jql', 5, 5, 'description')->willThrow(new \Exception('Anything')); + $this->api->search('test jql', 5, 5, 'description')->willThrow(new Exception('Anything')); $walker = $this->createWalker(5); $walker->push('test jql', 'description'); @@ -209,7 +210,7 @@ public function testAnyExceptionOnSecondPage() public function testSetDelegateError() { - $this->expectException('\Exception'); + $this->expectException(Exception::class); $this->expectExceptionMessage('passed argument is not callable'); $walker = $this->createWalker();