From 9c6aa38bdaabfe96eb3e23ffe30ad2da2ffe0fda Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 9 Sep 2024 16:07:19 +0200 Subject: [PATCH] Give testing some love --- .github/workflows/tests.yml | 7 ++-- .gitignore | 1 + appveyor.yml | 6 ++-- phpunit | 13 ++++++++ src/Mbstring/bootstrap80.php | 4 +-- src/Php84/bootstrap.php | 4 +-- src/Util/TestListenerTrait.php | 12 ++++++- tests/Compiler.php | 2 +- .../Icu/AbstractIntlDateFormatterTest.php | 33 ++++++++++++------- tests/update-unidata.php | 2 +- 10 files changed, 60 insertions(+), 24 deletions(-) create mode 100755 phpunit diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c3f828ffd..dbb2e9190 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,6 @@ jobs: env: COMPOSER_ROOT_VERSION: 1.x-dev - SYMFONY_PHPUNIT_VERSION: 8.5 strategy: matrix: @@ -41,10 +40,12 @@ jobs: tools: "composer:v2" - name: Install dependencies - run: composer --prefer-source --no-progress --ansi install + run: | + composer --prefer-source --no-progress --ansi install + ./phpunit install - name: Run tests run: | ok=0 - ./vendor/bin/simple-phpunit || ok=1 + ./phpunit || ok=1 [[ "${{ matrix.mode }}" = experimental ]] || (exit $ok) diff --git a/.gitignore b/.gitignore index a9246d0fd..b025ac2c9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ .phpunit.result.cache composer.lock phpunit.xml +.phpunit vendor/ /tests/unicode diff --git a/appveyor.yml b/appveyor.yml index 9df8b9a65..93b8c784d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,8 +10,8 @@ cache: init: - SET PATH=c:\php;%PATH% - SET COMPOSER_NO_INTERACTION=1 + - SET COMPOSER_ROOT_VERSION=1.x-dev - SET PHP=1 - - SET SYMFONY_PHPUNIT_VERSION=8.5 install: - cinst wget @@ -41,8 +41,8 @@ install: - appveyor DownloadFile https://github.com/composer/composer/releases/download/2.7.9/composer.phar - cd c:\projects\polyfill - mkdir %APPDATA%\Composer && copy /Y .github\composer-config.json %APPDATA%\Composer\config.json - - SET COMPOSER_ROOT_VERSION=1.x-dev - composer update --prefer-source --no-progress --ansi + - php -d allow_url_fopen=0 ./phpunit install test_script: - - php -d allow_url_fopen=0 ./vendor/symfony/phpunit-bridge/bin/simple-phpunit + - php -d allow_url_fopen=0 ./phpunit diff --git a/phpunit b/phpunit new file mode 100755 index 000000000..82cf9caa3 --- /dev/null +++ b/phpunit @@ -0,0 +1,13 @@ +#!/usr/bin/env php +name && false === strpos($originalSignature, '|null') && false !== strpos($polyfillSignature, '|null')) { + // Added to PHP 8.2.14/8.3.1 + $originalSignature .= '|null'; + } + + if (false === strpos($bootstrap->getPath(), '80.php')) { + // mixed return type cannot be used before PHP 8 + $originalSignature = str_replace(': mixed', '', $originalSignature); + } + $map = [ '?' => '', 'IDNA_DEFAULT' => \PHP_VERSION_ID >= 80100 ? 'IDNA_DEFAULT' : '0', @@ -131,7 +141,7 @@ function {$f['name']}{$f['signature']} 'array|string|null $from_encoding' => 'array|string $from_encoding', ]; - if (strtr($polyfillSignature, $map) !== $originalSignature) { + if (strtr($polyfillSignature, $map) !== str_replace('?', '', $originalSignature)) { $warnings[] = TestListener::warning("Incompatible signature for PHP >= 8:\n- {$f['name']}$originalSignature\n+ {$f['name']}$polyfillSignature"); } } diff --git a/tests/Compiler.php b/tests/Compiler.php index bd61adc6e..85538460b 100644 --- a/tests/Compiler.php +++ b/tests/Compiler.php @@ -16,7 +16,7 @@ * and charset data to a format suitable for other Utf8 classes. * * See https://unicode.org/Public/UNIDATA/ for unicode data - * See https://github.com/unicode-org/cldr/blob/master/common/transforms/ for Latin-ASCII.xml + * See https://github.com/unicode-org/cldr/blob/main/common/transforms/ for Latin-ASCII.xml * * @author Nicolas Grekas * diff --git a/tests/Intl/Icu/AbstractIntlDateFormatterTest.php b/tests/Intl/Icu/AbstractIntlDateFormatterTest.php index 3e01dfa10..7761353e3 100644 --- a/tests/Intl/Icu/AbstractIntlDateFormatterTest.php +++ b/tests/Intl/Icu/AbstractIntlDateFormatterTest.php @@ -35,11 +35,11 @@ public function testConstructorDefaultTimeZone() { $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT); - $this->assertEquals(date_default_timezone_get(), $formatter->getTimeZoneId()); + $this->assertSame(date_default_timezone_get(), $formatter->getTimeZoneId()); - $this->assertEquals( + $this->assertSame( $this->getDateTime(0, $formatter->getTimeZoneId())->format('M j, Y, g:i A'), - $formatter->format(0) + str_replace("\u{202F}", ' ', $formatter->format(0)) ); } @@ -50,7 +50,7 @@ public function testConstructorWithoutDateType() { $formatter = $this->getDateFormatter('en', null, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN); - $this->assertSame('EEEE, MMMM d, y \'at\' h:mm a', $formatter->getPattern()); + $this->assertSame('EEEE, MMMM d, y \'at\' h:mm a', str_replace("\u{202F}", ' ', $formatter->getPattern())); } /** @@ -60,7 +60,7 @@ public function testConstructorWithoutTimeType() { $formatter = $this->getDateFormatter('en', IntlDateFormatter::SHORT, null, 'UTC', IntlDateFormatter::GREGORIAN); - $this->assertSame('M/d/yy, h:mm:ss a zzzz', $formatter->getPattern()); + $this->assertSame('M/d/yy, h:mm:ss a zzzz', str_replace("\u{202F}", ' ', $formatter->getPattern())); } /** @@ -498,7 +498,11 @@ public function testFormatIgnoresPatternForRelativeDateType() $datetime = \DateTime::createFromFormat('U', time(), new \DateTimeZone('GMT')); $datetime->setTime(0, 0, 0); - $this->assertSame('today at 12:00:00 AM Greenwich Mean Time', $formatter->format($datetime)); + $formatted = $formatter->format($datetime); + $formatted = str_replace(' at ', ', ', $formatted); + $formatted = str_replace("\u{202F}", ' ', $formatted); + + $this->assertSame('today, 12:00:00 AM Greenwich Mean Time', $formatted); } /** @@ -507,7 +511,7 @@ public function testFormatIgnoresPatternForRelativeDateType() public function testDateAndTimeType($timestamp, $datetype, $timetype, $expected) { $formatter = $this->getDateFormatter('en', $datetype, $timetype, 'UTC'); - $this->assertSame($expected, $formatter->format($timestamp)); + $this->assertSame($expected, str_replace("\u{202F}", ' ', $formatter->format($timestamp))); } public static function dateAndTimeTypeProvider() @@ -533,7 +537,14 @@ public function testRelativeDateType($timestamp, $datetype, $timetype, $expected $datetime->setTime(0, 0, 0); $formatter = $this->getDateFormatter('en', $datetype, $timetype, 'UTC'); - $this->assertSame($expected, $formatter->format($datetime)); + + $formatted = $formatter->format($datetime); + + // Ignore differences that vary by version of PHP or ICU + $formatted = str_replace(' at ', ', ', $formatted); + $formatted = str_replace("\u{202F}", ' ', $formatted); + + $this->assertSame($expected, $formatted); } public static function relativeDateTypeProvider() @@ -545,17 +556,17 @@ public static function relativeDateTypeProvider() [0, IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, '1/1/70'], [time(), IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, 'today'], - [time(), IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::FULL, 'today at 12:00:00 AM Coordinated Universal Time'], + [time(), IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::FULL, 'today, 12:00:00 AM Coordinated Universal Time'], [time(), IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::LONG, 'today, 12:00:00 AM UTC'], [time(), IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::SHORT, 'today, 12:00 AM'], [strtotime('-1 day', time()), IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, 'yesterday'], - [strtotime('-1 day', time()), IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::FULL, 'yesterday at 12:00:00 AM Coordinated Universal Time'], + [strtotime('-1 day', time()), IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::FULL, 'yesterday, 12:00:00 AM Coordinated Universal Time'], [strtotime('-1 day', time()), IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::LONG, 'yesterday, 12:00:00 AM UTC'], [strtotime('-1 day', time()), IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::SHORT, 'yesterday, 12:00 AM'], [strtotime('+1 day', time()), IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, 'tomorrow'], - [strtotime('+1 day', time()), IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::FULL, 'tomorrow at 12:00:00 AM Coordinated Universal Time'], + [strtotime('+1 day', time()), IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::FULL, 'tomorrow, 12:00:00 AM Coordinated Universal Time'], [strtotime('+1 day', time()), IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::LONG, 'tomorrow, 12:00:00 AM UTC'], [strtotime('+1 day', time()), IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::SHORT, 'tomorrow, 12:00 AM'], ]; diff --git a/tests/update-unidata.php b/tests/update-unidata.php index 1ce8c3863..10b082f93 100755 --- a/tests/update-unidata.php +++ b/tests/update-unidata.php @@ -21,7 +21,7 @@ file_put_contents(__DIR__.'/unicode/data/'.$file, $data); } -$data = file_get_contents('https://github.com/unicode-org/cldr/raw/master/common/transforms/Latin-ASCII.xml'); +$data = file_get_contents('https://github.com/unicode-org/cldr/raw/main/common/transforms/Latin-ASCII.xml'); file_put_contents(__DIR__.'/unicode/data/Latin-ASCII.xml', $data); Compiler::translitMap(__DIR__.'/../src/Iconv/Resources/charset/');