From dac187d5b6b06a128b06f8a76e033c3484d9da54 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Wed, 12 Feb 2025 22:41:14 +0100 Subject: [PATCH] Run unit tests again The `pear run-tests -r tests/` command executes the .phpt tests of which there are none for Net/URL2: pear run-tests -r tests/ Running 0 tests TOTAL TIME: 00:00 0 PASSED TESTS 0 SKIPPED TESTS Running with `-u` for the Phpunit test-cases fails with the pear test runner as long as it is not possible to install Phpunit via pear. As an intermediate, use the phpunit test runner from the project configuration (composer.json) and bootstrap across PHP versions. Additionally, touch the test-cases for updates of PhpUnit since versions 3/4/5 up to 12.0.2 (tested with PHP 5.3-8.4). --- .github/workflows/ci.yml | 4 ++++ composer.json | 3 +++ phpunit.xml.dist | 2 +- tests/Net/URL2Test.php | 24 +++++++++++++++++------- tests/bootstrap.php | 20 ++++++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 tests/bootstrap.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d029591..164e22e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,10 @@ jobs: with: php-version: ${{ matrix.php-version }} ini-values: include_path=.:/usr/share/php:pear/usr/share/php + tools: composer:2.2 + - name: Install dependencies + run: composer install - name: Run tests run: | + composer test pear run-tests -r tests/ diff --git a/composer.json b/composer.json index c8a0c12..772e901 100644 --- a/composer.json +++ b/composer.json @@ -46,5 +46,8 @@ }, "require-dev": { "phpunit/phpunit": ">=3.3.0" + }, + "scripts": { + "test": "phpunit" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2fee318..a176b9f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,4 +1,4 @@ -assertEquals($assertion, Net_URL2::removeDotSegments($path)); @@ -570,7 +573,7 @@ public function testRemoveDotSegmentsLoopLimit() * @see testGetQueryVariables * @return array */ - public function provideQueryStrings() + public static function provideQueryStrings() { // If the second (expected) value is set or not null, parse_str() differs. // Notes on PHP differences with each entry/block @@ -632,6 +635,7 @@ public function provideQueryStrings() * @covers Net_URL2::_queryKeyBracketOffset * @return void */ + #[PHPUnit\Framework\Attributes\DataProvider('provideQueryStrings')] public function testGetQueryVariables($query, $expected = null, array $options = array() ) { @@ -663,7 +667,7 @@ public function testGetQueryVariables($query, $expected = null, * @return array * @see testHostAndPort */ - public function provideHostAndPort() + public static function provideHostAndPort() { return array( array('[::1]', '[::1]', false), @@ -699,6 +703,7 @@ public function provideHostAndPort() * @link http://tools.ietf.org/html/rfc3986#section-3.2 * @link http://tools.ietf.org/html/rfc3986#section-3.2.3 */ + #[PHPUnit\Framework\Attributes\DataProvider('provideHostAndPort')] public function testHostAndPort($authority, $expectedHost, $expectedPort) { $uri = "http://{$authority}"; @@ -762,6 +767,8 @@ public function test19315() Net_URL2::removeDotSegments($nonStringObject); } catch (PHPUnit_Framework_Error $error) { $this->addToAssertionCount(1); + } catch (Throwable $error) { + $this->addToAssertionCount(1); } if (!isset($error)) { @@ -816,7 +823,7 @@ public function test19684() * @see testConstructSelf * @return array */ - public function provideEquivalentUrlLists() + public static function provideEquivalentUrlLists() { return array( // String equivalence: @@ -853,6 +860,7 @@ public function provideEquivalentUrlLists() * * @dataProvider provideEquivalentUrlLists */ + #[PHPUnit\Framework\Attributes\DataProvider('provideEquivalentUrlLists')] public function testNormalize() { $urls = func_get_args(); @@ -897,7 +905,7 @@ public function testMagicSetGet() * @return array * @see testComponentRecompositionAndNormalization */ - public function provideComposedAndNormalized() + public static function provideComposedAndNormalized() { return array( array(''), @@ -926,6 +934,7 @@ public function provideComposedAndNormalized() * @link https://pear.php.net/bugs/bug.php?id=20418 * @see testExampleUri */ + #[PHPUnit\Framework\Attributes\DataProvider('provideComposedAndNormalized')] public function testComponentRecompositionAndNormalization($uri) { $url = new Net_URL2($uri); @@ -942,6 +951,7 @@ public function testComponentRecompositionAndNormalization($uri) * @coversNothing * @return void */ + #[PHPUnit\Framework\Attributes\DataProvider('provideEquivalentUrlLists')] public function testConstructSelf() { $urls = func_get_args(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..8e22f77 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,20 @@ + + * @license https://spdx.org/licenses/BSD-3-Clause BSD-3-Clause + * @link https://tools.ietf.org/html/rfc3986 + */ + +if (!class_exists('PHPUnit_Framework_TestCase')) +{ + class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); +} + +require __DIR__ . '/../Net/URL2.php';