Skip to content

Commit

Permalink
Give testing some love
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 10, 2024
1 parent c5ce28b commit 4da6db7
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 22 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:

env:
COMPOSER_ROOT_VERSION: 1.x-dev
SYMFONY_PHPUNIT_VERSION: 8.5

strategy:
matrix:
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
.phpunit.result.cache
composer.lock
phpunit.xml
.phpunit
vendor/
/tests/unicode
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env php
<?php

if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\nPlease run `composer update` before running this command.\n";
exit(1);
}
if (!getenv('SYMFONY_PHPUNIT_VERSION')) {
putenv('SYMFONY_PHPUNIT_VERSION=8.5');
}

putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
require __DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';
4 changes: 2 additions & 2 deletions src/Php84/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function array_all(array $array, callable $callback): bool { return p\Php84::arr

if (extension_loaded('mbstring')) {
if (!function_exists('mb_ucfirst')) {
function mb_ucfirst($string, ?string $encoding = null): string { return p\Php84::mb_ucfirst($string, $encoding); }
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Php84::mb_ucfirst($string, $encoding); }
}

if (!function_exists('mb_lcfirst')) {
function mb_lcfirst($string, ?string $encoding = null): string { return p\Php84::mb_lcfirst($string, $encoding); }
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Php84::mb_lcfirst($string, $encoding); }
}

if (!function_exists('mb_trim')) {
Expand Down
10 changes: 9 additions & 1 deletion src/Util/TestListenerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ function {$f['name']}{$f['signature']}
$polyfillSignature = ReflectionCaster::castFunctionAbstract(new \ReflectionFunction($testNamespace.'\\'.$f['name']), [], new Stub(), true);
$polyfillSignature = ReflectionCaster::getSignature($polyfillSignature);

if ('mb_get_info' === $r->name && false === strpos($originalSignature, '|null') && false !== strpos($polyfillSignature, '|null')) {
// Added to PHP 8.2.14/8.3.1
$originalSignature .= '|null';
}

// mixed return type cannot be used before PHP 8
$originalSignature = str_replace(': mixed', '', $originalSignature);

$map = [
'?' => '',
'IDNA_DEFAULT' => \PHP_VERSION_ID >= 80100 ? 'IDNA_DEFAULT' : '0',
Expand All @@ -131,7 +139,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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <p@tchwork.com>
*
Expand Down
33 changes: 22 additions & 11 deletions tests/Intl/Icu/AbstractIntlDateFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}

Expand All @@ -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()));
}

/**
Expand All @@ -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()));
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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'],
];
Expand Down
2 changes: 1 addition & 1 deletion tests/update-unidata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
Expand Down

0 comments on commit 4da6db7

Please sign in to comment.