Skip to content

Commit 0ef7d4e

Browse files
Give testing some love
1 parent c5ce28b commit 0ef7d4e

File tree

16 files changed

+91
-36
lines changed

16 files changed

+91
-36
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212

1313
env:
1414
COMPOSER_ROOT_VERSION: 1.x-dev
15-
SYMFONY_PHPUNIT_VERSION: 8.5
1615

1716
strategy:
1817
matrix:
@@ -41,10 +40,12 @@ jobs:
4140
tools: "composer:v2"
4241

4342
- name: Install dependencies
44-
run: composer --prefer-source --no-progress --ansi install
43+
run: |
44+
composer --prefer-source --no-progress --ansi install
45+
./phpunit install
4546
4647
- name: Run tests
4748
run: |
4849
ok=0
49-
./vendor/bin/simple-phpunit || ok=1
50+
./phpunit || ok=1
5051
[[ "${{ matrix.mode }}" = experimental ]] || (exit $ok)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
.phpunit.result.cache
44
composer.lock
55
phpunit.xml
6+
.phpunit
67
vendor/
78
/tests/unicode

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ cache:
1010
init:
1111
- SET PATH=c:\php;%PATH%
1212
- SET COMPOSER_NO_INTERACTION=1
13+
- SET COMPOSER_ROOT_VERSION=1.x-dev
1314
- SET PHP=1
14-
- SET SYMFONY_PHPUNIT_VERSION=8.5
1515

1616
install:
1717
- cinst wget
@@ -41,8 +41,8 @@ install:
4141
- appveyor DownloadFile https://github.com/composer/composer/releases/download/2.7.9/composer.phar
4242
- cd c:\projects\polyfill
4343
- mkdir %APPDATA%\Composer && copy /Y .github\composer-config.json %APPDATA%\Composer\config.json
44-
- SET COMPOSER_ROOT_VERSION=1.x-dev
4544
- composer update --prefer-source --no-progress --ansi
45+
- php -d allow_url_fopen=0 ./phpunit install
4646

4747
test_script:
48-
- php -d allow_url_fopen=0 ./vendor/symfony/phpunit-bridge/bin/simple-phpunit
48+
- php -d allow_url_fopen=0 ./phpunit

phpunit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
5+
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\nPlease run `composer update` before running this command.\n";
6+
exit(1);
7+
}
8+
if (!getenv('SYMFONY_PHPUNIT_VERSION')) {
9+
putenv('SYMFONY_PHPUNIT_VERSION=8.5');
10+
}
11+
12+
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
13+
require __DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit';

src/Apcu/bootstrap80.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function apcu_delete($key): array|bool { return p\Apcu::apcu_delete($key); }
2222
function apcu_exists($key): array|bool { return p\Apcu::apcu_exists($key); }
2323
}
2424
if (!function_exists('apcu_fetch')) {
25-
function apcu_fetch($key, &$success = null): mixed { return p\Apcu::apcu_fetch($key, $success); }
25+
function apcu_fetch($key, &$success = null) { return p\Apcu::apcu_fetch($key, $success); }
2626
}
2727
if (!function_exists('apcu_store')) {
2828
function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_store($key, $value, (int) $ttl); }

src/Intl/Idn/Idn.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ final class Idn
145145
*/
146146
public static function idn_to_ascii($domainName, $options = self::IDNA_DEFAULT, $variant = self::INTL_IDNA_VARIANT_UTS46, &$idna_info = [])
147147
{
148+
if (\PHP_VERSION_ID > 80400 && '' === $domainName) {
149+
throw new \ValueError('idn_to_ascii(): Argument #1 ($domain) cannot be empty');
150+
}
151+
148152
if (self::INTL_IDNA_VARIANT_2003 === $variant) {
149153
@trigger_error('idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated', \E_USER_DEPRECATED);
150154
}
@@ -198,6 +202,10 @@ public static function idn_to_ascii($domainName, $options = self::IDNA_DEFAULT,
198202
*/
199203
public static function idn_to_utf8($domainName, $options = self::IDNA_DEFAULT, $variant = self::INTL_IDNA_VARIANT_UTS46, &$idna_info = [])
200204
{
205+
if (\PHP_VERSION_ID > 80400 && '' === $domainName) {
206+
throw new \ValueError('idn_to_utf8(): Argument #1 ($domain) cannot be empty');
207+
}
208+
201209
if (self::INTL_IDNA_VARIANT_2003 === $variant) {
202210
@trigger_error('idn_to_utf8(): INTL_IDNA_VARIANT_2003 is deprecated', \E_USER_DEPRECATED);
203211
}

src/Mbstring/bootstrap80.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $
133133
}
134134

135135
if (!function_exists('mb_ucfirst')) {
136-
function mb_ucfirst($string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
136+
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
137137
}
138138

139139
if (!function_exists('mb_lcfirst')) {
140-
function mb_lcfirst($string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
140+
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
141141
}
142142

143143
if (!function_exists('mb_trim')) {

src/Php84/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ function array_all(array $array, callable $callback): bool { return p\Php84::arr
4141

4242
if (extension_loaded('mbstring')) {
4343
if (!function_exists('mb_ucfirst')) {
44-
function mb_ucfirst($string, ?string $encoding = null): string { return p\Php84::mb_ucfirst($string, $encoding); }
44+
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Php84::mb_ucfirst($string, $encoding); }
4545
}
4646

4747
if (!function_exists('mb_lcfirst')) {
48-
function mb_lcfirst($string, ?string $encoding = null): string { return p\Php84::mb_lcfirst($string, $encoding); }
48+
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Php84::mb_lcfirst($string, $encoding); }
4949
}
5050

5151
if (!function_exists('mb_trim')) {

src/Util/TestListenerTrait.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ function {$f['name']}{$f['signature']}
123123
$polyfillSignature = ReflectionCaster::castFunctionAbstract(new \ReflectionFunction($testNamespace.'\\'.$f['name']), [], new Stub(), true);
124124
$polyfillSignature = ReflectionCaster::getSignature($polyfillSignature);
125125

126+
if ('mb_get_info' === $r->name && false === strpos($originalSignature, '|null') && false !== strpos($polyfillSignature, '|null')) {
127+
// Added to PHP 8.2.14/8.3.1
128+
$originalSignature .= '|null';
129+
}
130+
131+
if (false === strpos($bootstrap->getPath(), '80.php')) {
132+
// mixed return type cannot be used before PHP 8
133+
$originalSignature = str_replace(': mixed', '', $originalSignature);
134+
}
135+
126136
$map = [
127137
'?' => '',
128138
'IDNA_DEFAULT' => \PHP_VERSION_ID >= 80100 ? 'IDNA_DEFAULT' : '0',
@@ -131,7 +141,7 @@ function {$f['name']}{$f['signature']}
131141
'array|string|null $from_encoding' => 'array|string $from_encoding',
132142
];
133143

134-
if (strtr($polyfillSignature, $map) !== $originalSignature) {
144+
if (strtr($polyfillSignature, $map) !== str_replace('?', '', $originalSignature)) {
135145
$warnings[] = TestListener::warning("Incompatible signature for PHP >= 8:\n- {$f['name']}$originalSignature\n+ {$f['name']}$polyfillSignature");
136146
}
137147
}

tests/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* and charset data to a format suitable for other Utf8 classes.
1717
*
1818
* See https://unicode.org/Public/UNIDATA/ for unicode data
19-
* See https://github.com/unicode-org/cldr/blob/master/common/transforms/ for Latin-ASCII.xml
19+
* See https://github.com/unicode-org/cldr/blob/main/common/transforms/ for Latin-ASCII.xml
2020
*
2121
* @author Nicolas Grekas <p@tchwork.com>
2222
*

0 commit comments

Comments
 (0)