From 5a27158781ef89e7ceb45bdf55426f9b1e696371 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 9 Sep 2024 18:14:13 +0200 Subject: [PATCH] Bump to PHP 8.1 --- .github/workflows/tests.yml | 4 - composer.json | 11 +- phpunit | 2 +- phpunit.xml.dist | 18 +- src/Apcu/bootstrap.php | 22 +- src/Apcu/bootstrap80.php | 75 ---- src/Apcu/composer.json | 2 +- src/Ctype/Ctype.php | 4 +- src/Ctype/bootstrap.php | 26 +- src/Ctype/bootstrap80.php | 46 --- src/Ctype/composer.json | 2 +- src/Iconv/Iconv.php | 8 +- src/Iconv/bootstrap.php | 32 +- src/Iconv/bootstrap80.php | 76 ----- src/Iconv/composer.json | 2 +- src/Intl/Grapheme/Grapheme.php | 14 +- src/Intl/Grapheme/bootstrap.php | 22 +- src/Intl/Grapheme/bootstrap80.php | 50 --- src/Intl/Grapheme/composer.json | 2 +- src/Intl/Icu/IntlDateFormatter.php | 12 +- src/Intl/Icu/NumberFormatter.php | 16 +- src/Intl/Icu/bootstrap.php | 12 +- src/Intl/Icu/bootstrap80.php | 25 -- src/Intl/Icu/composer.json | 2 +- src/Intl/Idn/bootstrap.php | 26 +- src/Intl/Idn/bootstrap80.php | 125 ------- src/Intl/Idn/composer.json | 2 +- src/Intl/MessageFormatter/composer.json | 2 +- src/Intl/Normalizer/Normalizer.php | 4 - src/Intl/Normalizer/bootstrap.php | 8 +- src/Intl/Normalizer/bootstrap80.php | 19 -- src/Intl/Normalizer/composer.json | 2 +- src/Mbstring/Mbstring.php | 29 +- src/Mbstring/bootstrap.php | 81 +++-- src/Mbstring/bootstrap80.php | 167 --------- src/Mbstring/composer.json | 2 +- src/Php73/Php73.php | 43 --- src/Php73/Resources/stubs/JsonException.php | 16 - src/Php73/bootstrap.php | 31 -- src/Php73/composer.json | 9 +- src/Php74/Php74.php | 94 ----- src/Php74/bootstrap.php | 28 -- src/Php74/composer.json | 8 +- src/Php80/Php80.php | 115 ------- src/Php80/PhpToken.php | 103 ------ src/Php80/Resources/stubs/Attribute.php | 31 -- src/Php80/Resources/stubs/PhpToken.php | 16 - src/Php80/Resources/stubs/Stringable.php | 20 -- .../Resources/stubs/UnhandledMatchError.php | 16 - src/Php80/Resources/stubs/ValueError.php | 16 - src/Php80/bootstrap.php | 42 --- src/Php80/composer.json | 9 +- src/Php81/Php81.php | 37 -- src/Php81/Resources/stubs/CURLStringFile.php | 51 --- .../Resources/stubs/ReturnTypeWillChange.php | 20 -- src/Php81/bootstrap.php | 28 -- src/Php81/composer.json | 9 +- src/Php82/composer.json | 2 +- src/Php83/bootstrap.php | 8 +- src/Php83/bootstrap81.php | 22 -- src/Php83/composer.json | 2 +- src/Php84/composer.json | 2 +- src/Util/TestListener.php | 81 ++++- src/Util/TestListenerForV7.php | 91 ----- src/Util/TestListenerForV9.php | 91 ----- src/Util/TestListenerTrait.php | 16 +- src/Util/composer.json | 2 +- src/Uuid/Uuid.php | 42 +-- src/Uuid/bootstrap.php | 28 +- src/Uuid/bootstrap80.php | 89 ----- src/Uuid/composer.json | 2 +- src/bootstrap.php | 16 - tests/Iconv/IconvTest.php | 15 - tests/Intl/Grapheme/GraphemeTest.php | 58 +--- .../Intl/Icu/AbstractNumberFormatterTest.php | 30 +- .../Verification/IntlDateFormatterTest.php | 17 - tests/Intl/Idn/IdnTest.php | 39 --- tests/Intl/Normalizer/NormalizerTest.php | 11 +- tests/Mbstring/MbstringTest.php | 165 ++------- tests/Php73/Php73Test.php | 169 --------- tests/Php73/fixtures/en.res | Bin 316 -> 0 bytes tests/Php73/generator.php | 19 -- tests/Php74/Php74Test.php | 142 -------- tests/Php80/Php80Test.php | 322 ------------------ tests/Php80/PhpTokenTest.php | 83 ----- tests/Php81/CURLStringFileTest.php | 59 ---- tests/Php81/Php81Test.php | 44 --- tests/Php81/fixtures/curl-echo-server.php | 19 -- tests/Php82/Php82Test.php | 6 - tests/Php84/Php84Test.php | 6 +- tests/Uuid/UuidTest.php | 88 ++--- 91 files changed, 317 insertions(+), 3163 deletions(-) delete mode 100644 src/Apcu/bootstrap80.php delete mode 100644 src/Ctype/bootstrap80.php delete mode 100644 src/Iconv/bootstrap80.php delete mode 100644 src/Intl/Grapheme/bootstrap80.php delete mode 100644 src/Intl/Icu/bootstrap80.php delete mode 100644 src/Intl/Idn/bootstrap80.php delete mode 100644 src/Intl/Normalizer/bootstrap80.php delete mode 100644 src/Mbstring/bootstrap80.php delete mode 100644 src/Php73/Php73.php delete mode 100644 src/Php73/Resources/stubs/JsonException.php delete mode 100644 src/Php73/bootstrap.php delete mode 100644 src/Php74/Php74.php delete mode 100644 src/Php74/bootstrap.php delete mode 100644 src/Php80/Php80.php delete mode 100644 src/Php80/PhpToken.php delete mode 100644 src/Php80/Resources/stubs/Attribute.php delete mode 100644 src/Php80/Resources/stubs/PhpToken.php delete mode 100644 src/Php80/Resources/stubs/Stringable.php delete mode 100644 src/Php80/Resources/stubs/UnhandledMatchError.php delete mode 100644 src/Php80/Resources/stubs/ValueError.php delete mode 100644 src/Php80/bootstrap.php delete mode 100644 src/Php81/Php81.php delete mode 100644 src/Php81/Resources/stubs/CURLStringFile.php delete mode 100644 src/Php81/Resources/stubs/ReturnTypeWillChange.php delete mode 100644 src/Php81/bootstrap.php delete mode 100644 src/Php83/bootstrap81.php delete mode 100644 src/Util/TestListenerForV7.php delete mode 100644 src/Util/TestListenerForV9.php delete mode 100644 src/Uuid/bootstrap80.php delete mode 100644 tests/Php73/Php73Test.php delete mode 100644 tests/Php73/fixtures/en.res delete mode 100644 tests/Php73/generator.php delete mode 100644 tests/Php74/Php74Test.php delete mode 100644 tests/Php80/Php80Test.php delete mode 100644 tests/Php80/PhpTokenTest.php delete mode 100644 tests/Php81/CURLStringFileTest.php delete mode 100644 tests/Php81/Php81Test.php delete mode 100644 tests/Php81/fixtures/curl-echo-server.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dbb2e9190..857e86b5c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,10 +16,6 @@ jobs: strategy: matrix: include: - - php: '7.2' - - php: '7.3' - - php: '7.4' - - php: '8.0' - php: '8.1' - php: '8.2' - php: '8.3' diff --git a/composer.json b/composer.json index a639d51ca..82eed117a 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "require-dev": { - "symfony/intl": "^5.4|^6.4", + "symfony/intl": "^6.4", "symfony/phpunit-bridge": "^6.4", - "symfony/var-dumper": "^5.4|^6.4" + "symfony/var-dumper": "^6.4" }, "replace": { "symfony/polyfill-apcu": "self.version", @@ -64,10 +64,7 @@ "src/Intl/Normalizer/Resources/stubs", "src/Php84/Resources/stubs", "src/Php83/Resources/stubs", - "src/Php82/Resources/stubs", - "src/Php81/Resources/stubs", - "src/Php80/Resources/stubs", - "src/Php73/Resources/stubs" + "src/Php82/Resources/stubs" ] }, "minimum-stability": "dev" diff --git a/phpunit b/phpunit index 82cf9caa3..0a6803dd9 100755 --- a/phpunit +++ b/phpunit @@ -6,7 +6,7 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) { exit(1); } if (!getenv('SYMFONY_PHPUNIT_VERSION')) { - putenv('SYMFONY_PHPUNIT_VERSION=8.5'); + putenv('SYMFONY_PHPUNIT_VERSION=9.6'); } putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit'); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 59c84357c..8794080f2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ @@ -15,15 +15,15 @@ - - + + ./src/ - - ./src/*/Resources - ./src/*/*/Resources - - - + + + ./src/*/Resources + ./src/*/*/Resources + + diff --git a/src/Apcu/bootstrap.php b/src/Apcu/bootstrap.php index 96b2706ad..058d82b8a 100644 --- a/src/Apcu/bootstrap.php +++ b/src/Apcu/bootstrap.php @@ -15,41 +15,37 @@ return; } -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (extension_loaded('Zend Data Cache')) { if (!function_exists('apcu_add')) { - function apcu_add($key, $value = null, $ttl = 0) { return p\Apcu::apcu_add($key, $value, $ttl); } + function apcu_add($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_add($key, $value, (int) $ttl); } } if (!function_exists('apcu_delete')) { - function apcu_delete($key) { return p\Apcu::apcu_delete($key); } + function apcu_delete($key): array|bool { return p\Apcu::apcu_delete($key); } } if (!function_exists('apcu_exists')) { - function apcu_exists($key) { return p\Apcu::apcu_exists($key); } + function apcu_exists($key): array|bool { return p\Apcu::apcu_exists($key); } } if (!function_exists('apcu_fetch')) { function apcu_fetch($key, &$success = null) { return p\Apcu::apcu_fetch($key, $success); } } if (!function_exists('apcu_store')) { - function apcu_store($key, $value = null, $ttl = 0) { return p\Apcu::apcu_store($key, $value, $ttl); } + function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_store($key, $value, (int) $ttl); } } } else { if (!function_exists('apcu_add')) { - function apcu_add($key, $value = null, $ttl = 0) { return apc_add($key, $value, $ttl); } + function apcu_add($key, mixed $value, ?int $ttl = 0): array|bool { return apc_add($key, $value, (int) $ttl); } } if (!function_exists('apcu_delete')) { - function apcu_delete($key) { return apc_delete($key); } + function apcu_delete($key): array|bool { return apc_delete($key); } } if (!function_exists('apcu_exists')) { - function apcu_exists($key) { return apc_exists($key); } + function apcu_exists($key): array|bool { return apc_exists($key); } } if (!function_exists('apcu_fetch')) { function apcu_fetch($key, &$success = null) { return apc_fetch($key, $success); } } if (!function_exists('apcu_store')) { - function apcu_store($key, $value = null, $ttl = 0) { return apc_store($key, $value, $ttl); } + function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return apc_store($key, $value, (int) $ttl); } } } @@ -75,7 +71,7 @@ function apcu_sma_info($limited = false) { return apc_sma_info($limited); } if (!class_exists('APCuIterator', false) && class_exists('APCIterator', false)) { class APCuIterator extends APCIterator { - public function __construct($search = null, $format = \APC_ITER_ALL, $chunk_size = 100, $list = \APC_LIST_ACTIVE) + public function __construct($search = null, $format = APC_ITER_ALL, $chunk_size = 100, $list = APC_LIST_ACTIVE) { parent::__construct('user', $search, $format, $chunk_size, $list); } diff --git a/src/Apcu/bootstrap80.php b/src/Apcu/bootstrap80.php deleted file mode 100644 index 603196917..000000000 --- a/src/Apcu/bootstrap80.php +++ /dev/null @@ -1,75 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Apcu as p; - -if (extension_loaded('Zend Data Cache')) { - if (!function_exists('apcu_add')) { - function apcu_add($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_add($key, $value, (int) $ttl); } - } - if (!function_exists('apcu_delete')) { - function apcu_delete($key): array|bool { return p\Apcu::apcu_delete($key); } - } - if (!function_exists('apcu_exists')) { - function apcu_exists($key): array|bool { return p\Apcu::apcu_exists($key); } - } - if (!function_exists('apcu_fetch')) { - function apcu_fetch($key, &$success = null) { return p\Apcu::apcu_fetch($key, $success); } - } - if (!function_exists('apcu_store')) { - function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return p\Apcu::apcu_store($key, $value, (int) $ttl); } - } -} else { - if (!function_exists('apcu_add')) { - function apcu_add($key, mixed $value, ?int $ttl = 0): array|bool { return apc_add($key, $value, (int) $ttl); } - } - if (!function_exists('apcu_delete')) { - function apcu_delete($key): array|bool { return apc_delete($key); } - } - if (!function_exists('apcu_exists')) { - function apcu_exists($key): array|bool { return apc_exists($key); } - } - if (!function_exists('apcu_fetch')) { - function apcu_fetch($key, &$success = null) { return apc_fetch($key, $success); } - } - if (!function_exists('apcu_store')) { - function apcu_store($key, mixed $value, ?int $ttl = 0): array|bool { return apc_store($key, $value, (int) $ttl); } - } -} - -if (!function_exists('apcu_cache_info')) { - function apcu_cache_info($limited = false) { return apc_cache_info('user', $limited); } -} -if (!function_exists('apcu_cas')) { - function apcu_cas($key, $old, $new) { return apc_cas($key, $old, $new); } -} -if (!function_exists('apcu_clear_cache')) { - function apcu_clear_cache() { return apc_clear_cache('user'); } -} -if (!function_exists('apcu_dec')) { - function apcu_dec($key, $step = 1, &$success = false) { return apc_dec($key, $step, $success); } -} -if (!function_exists('apcu_inc')) { - function apcu_inc($key, $step = 1, &$success = false) { return apc_inc($key, $step, $success); } -} -if (!function_exists('apcu_sma_info')) { - function apcu_sma_info($limited = false) { return apc_sma_info($limited); } -} - -if (!class_exists('APCuIterator', false) && class_exists('APCIterator', false)) { - class APCuIterator extends APCIterator - { - public function __construct($search = null, $format = APC_ITER_ALL, $chunk_size = 100, $list = APC_LIST_ACTIVE) - { - parent::__construct('user', $search, $format, $chunk_size, $list); - } - } -} diff --git a/src/Apcu/composer.json b/src/Apcu/composer.json index ba1b8743c..1de2f857e 100644 --- a/src/Apcu/composer.json +++ b/src/Apcu/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Apcu\\": "" }, diff --git a/src/Ctype/Ctype.php b/src/Ctype/Ctype.php index ba75a2c95..903b666d9 100644 --- a/src/Ctype/Ctype.php +++ b/src/Ctype/Ctype.php @@ -219,9 +219,7 @@ private static function convert_int_to_char_for_ctype($int, $function) return (string) $int; } - if (\PHP_VERSION_ID >= 80100) { - @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); - } + @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); if ($int < 0) { $int += 256; diff --git a/src/Ctype/bootstrap.php b/src/Ctype/bootstrap.php index d54524b31..ab2f8611d 100644 --- a/src/Ctype/bootstrap.php +++ b/src/Ctype/bootstrap.php @@ -11,40 +11,36 @@ use Symfony\Polyfill\Ctype as p; -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!function_exists('ctype_alnum')) { - function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); } + function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } } if (!function_exists('ctype_alpha')) { - function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); } + function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } } if (!function_exists('ctype_cntrl')) { - function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); } + function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } } if (!function_exists('ctype_digit')) { - function ctype_digit($text) { return p\Ctype::ctype_digit($text); } + function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } } if (!function_exists('ctype_graph')) { - function ctype_graph($text) { return p\Ctype::ctype_graph($text); } + function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } } if (!function_exists('ctype_lower')) { - function ctype_lower($text) { return p\Ctype::ctype_lower($text); } + function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } } if (!function_exists('ctype_print')) { - function ctype_print($text) { return p\Ctype::ctype_print($text); } + function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } } if (!function_exists('ctype_punct')) { - function ctype_punct($text) { return p\Ctype::ctype_punct($text); } + function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } } if (!function_exists('ctype_space')) { - function ctype_space($text) { return p\Ctype::ctype_space($text); } + function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } } if (!function_exists('ctype_upper')) { - function ctype_upper($text) { return p\Ctype::ctype_upper($text); } + function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } } if (!function_exists('ctype_xdigit')) { - function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); } + function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } } diff --git a/src/Ctype/bootstrap80.php b/src/Ctype/bootstrap80.php deleted file mode 100644 index ab2f8611d..000000000 --- a/src/Ctype/bootstrap80.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Ctype as p; - -if (!function_exists('ctype_alnum')) { - function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); } -} -if (!function_exists('ctype_alpha')) { - function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); } -} -if (!function_exists('ctype_cntrl')) { - function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); } -} -if (!function_exists('ctype_digit')) { - function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); } -} -if (!function_exists('ctype_graph')) { - function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); } -} -if (!function_exists('ctype_lower')) { - function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); } -} -if (!function_exists('ctype_print')) { - function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); } -} -if (!function_exists('ctype_punct')) { - function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); } -} -if (!function_exists('ctype_space')) { - function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); } -} -if (!function_exists('ctype_upper')) { - function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); } -} -if (!function_exists('ctype_xdigit')) { - function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); } -} diff --git a/src/Ctype/composer.json b/src/Ctype/composer.json index 131ca7adb..735076eb3 100644 --- a/src/Ctype/composer.json +++ b/src/Ctype/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "provide": { "ext-ctype": "*" diff --git a/src/Iconv/Iconv.php b/src/Iconv/Iconv.php index b4421449c..879bae578 100644 --- a/src/Iconv/Iconv.php +++ b/src/Iconv/Iconv.php @@ -514,14 +514,10 @@ public static function iconv_substr($s, $start, $length = 2147483647, $encoding $start += $slen; } if (0 > $start) { - if (\PHP_VERSION_ID < 80000) { - return false; - } - $start = 0; } if ($start >= $slen) { - return \PHP_VERSION_ID >= 80000 ? '' : false; + return ''; } $rx = $slen - $start; @@ -533,7 +529,7 @@ public static function iconv_substr($s, $start, $length = 2147483647, $encoding return ''; } if (0 > $length) { - return \PHP_VERSION_ID >= 80000 ? '' : false; + return ''; } if ($length > $rx) { diff --git a/src/Iconv/bootstrap.php b/src/Iconv/bootstrap.php index e629531fa..7f34d617c 100644 --- a/src/Iconv/bootstrap.php +++ b/src/Iconv/bootstrap.php @@ -15,10 +15,6 @@ return; } -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!defined('ICONV_IMPL')) { define('ICONV_IMPL', 'Symfony'); } @@ -33,52 +29,52 @@ } if (!function_exists('iconv')) { - function iconv($from_encoding, $to_encoding, $string) { return p\Iconv::iconv($from_encoding, $to_encoding, $string); } + function iconv(?string $from_encoding, ?string $to_encoding, ?string $string): string|false { return p\Iconv::iconv((string) $from_encoding, (string) $to_encoding, (string) $string); } } if (!function_exists('iconv_get_encoding')) { - function iconv_get_encoding($type = 'all') { return p\Iconv::iconv_get_encoding($type); } + function iconv_get_encoding(?string $type = 'all'): array|string|false { return p\Iconv::iconv_get_encoding((string) $type); } } if (!function_exists('iconv_set_encoding')) { - function iconv_set_encoding($type, $encoding) { return p\Iconv::iconv_set_encoding($type, $encoding); } + function iconv_set_encoding(?string $type, ?string $encoding): bool { return p\Iconv::iconv_set_encoding((string) $type, (string) $encoding); } } if (!function_exists('iconv_mime_encode')) { - function iconv_mime_encode($field_name, $field_value, $options = []) { return p\Iconv::iconv_mime_encode($field_name, $field_value, $options); } + function iconv_mime_encode(?string $field_name, ?string $field_value, ?array $options = []): string|false { return p\Iconv::iconv_mime_encode((string) $field_name, (string) $field_value, (array) $options); } } if (!function_exists('iconv_mime_decode_headers')) { - function iconv_mime_decode_headers($headers, $mode = 0, $encoding = null) { return p\Iconv::iconv_mime_decode_headers($headers, $mode, $encoding); } + function iconv_mime_decode_headers(?string $headers, ?int $mode = 0, ?string $encoding = null): array|false { return p\Iconv::iconv_mime_decode_headers((string) $headers, (int) $mode, $encoding); } } if (extension_loaded('mbstring')) { if (!function_exists('iconv_strlen')) { - function iconv_strlen($string, $encoding = null) { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strlen($string, $encoding); } + function iconv_strlen(?string $string, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strlen((string) $string, $encoding); } } if (!function_exists('iconv_strpos')) { - function iconv_strpos($haystack, $needle, $offset = 0, $encoding = null) { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strpos($haystack, $needle, $offset, $encoding); } + function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } } if (!function_exists('iconv_strrpos')) { - function iconv_strrpos($haystack, $needle, $encoding = null) { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strrpos($haystack, $needle, 0, $encoding); } + function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strrpos((string) $haystack, (string) $needle, 0, $encoding); } } if (!function_exists('iconv_substr')) { - function iconv_substr($string, $offset, $length = 2147483647, $encoding = null) { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_substr($string, $offset, $length, $encoding); } + function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_substr((string) $string, (int) $offset, $length, $encoding); } } if (!function_exists('iconv_mime_decode')) { function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEncoding = mb_internal_encoding(); null === $encoding && $encoding = p\Iconv::$internalEncoding; mb_internal_encoding($encoding); $decoded = mb_decode_mimeheader($string); mb_internal_encoding($currentMbEncoding); return $decoded; } } } else { if (!function_exists('iconv_strlen')) { - function iconv_strlen($string, $encoding = null) { return p\Iconv::iconv_strlen($string, $encoding); } + function iconv_strlen($string, $encoding = null): int|false { return p\Iconv::iconv_strlen($string, $encoding); } } if (!function_exists('iconv_strpos')) { - function iconv_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Iconv::iconv_strpos($haystack, $needle, $offset, $encoding); } + function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Iconv::iconv_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } } if (!function_exists('iconv_strrpos')) { - function iconv_strrpos($haystack, $needle, $encoding = null) { return p\Iconv::iconv_strrpos($haystack, $needle, $encoding); } + function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { return p\Iconv::iconv_strrpos((string) $haystack, (string) $needle, $encoding); } } if (!function_exists('iconv_substr')) { - function iconv_substr($string, $offset, $length = 2147483647, $encoding = null) { return p\Iconv::iconv_substr($string, $offset, $length, $encoding); } + function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { return p\Iconv::iconv_substr((string) $string, (string) $offset, $length, $encoding); } } if (!function_exists('iconv_mime_decode')) { - function iconv_mime_decode($string, $mode = 0, $encoding = null) { return p\Iconv::iconv_mime_decode($string, $mode, $encoding); } + function iconv_mime_decode(?string $string, ?int $mode = 0, ?string $encoding = null): string|false { return p\Iconv::iconv_mime_decode((string) $string, (int) $mode, $encoding); } } } diff --git a/src/Iconv/bootstrap80.php b/src/Iconv/bootstrap80.php deleted file mode 100644 index 2d0f12fdc..000000000 --- a/src/Iconv/bootstrap80.php +++ /dev/null @@ -1,76 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Iconv as p; - -if (!defined('ICONV_IMPL')) { - define('ICONV_IMPL', 'Symfony'); -} -if (!defined('ICONV_VERSION')) { - define('ICONV_VERSION', '1.0'); -} -if (!defined('ICONV_MIME_DECODE_STRICT')) { - define('ICONV_MIME_DECODE_STRICT', 1); -} -if (!defined('ICONV_MIME_DECODE_CONTINUE_ON_ERROR')) { - define('ICONV_MIME_DECODE_CONTINUE_ON_ERROR', 2); -} - -if (!function_exists('iconv')) { - function iconv(?string $from_encoding, ?string $to_encoding, ?string $string): string|false { return p\Iconv::iconv((string) $from_encoding, (string) $to_encoding, (string) $string); } -} -if (!function_exists('iconv_get_encoding')) { - function iconv_get_encoding(?string $type = 'all'): array|string|false { return p\Iconv::iconv_get_encoding((string) $type); } -} -if (!function_exists('iconv_set_encoding')) { - function iconv_set_encoding(?string $type, ?string $encoding): bool { return p\Iconv::iconv_set_encoding((string) $type, (string) $encoding); } -} -if (!function_exists('iconv_mime_encode')) { - function iconv_mime_encode(?string $field_name, ?string $field_value, ?array $options = []): string|false { return p\Iconv::iconv_mime_encode((string) $field_name, (string) $field_value, (array) $options); } -} -if (!function_exists('iconv_mime_decode_headers')) { - function iconv_mime_decode_headers(?string $headers, ?int $mode = 0, ?string $encoding = null): array|false { return p\Iconv::iconv_mime_decode_headers((string) $headers, (int) $mode, $encoding); } -} - -if (extension_loaded('mbstring')) { - if (!function_exists('iconv_strlen')) { - function iconv_strlen(?string $string, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strlen((string) $string, $encoding); } - } - if (!function_exists('iconv_strpos')) { - function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } - } - if (!function_exists('iconv_strrpos')) { - function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_strrpos((string) $haystack, (string) $needle, 0, $encoding); } - } - if (!function_exists('iconv_substr')) { - function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { null === $encoding && $encoding = p\Iconv::$internalEncoding; return mb_substr((string) $string, (int) $offset, $length, $encoding); } - } - if (!function_exists('iconv_mime_decode')) { - function iconv_mime_decode($string, $mode = 0, $encoding = null) { $currentMbEncoding = mb_internal_encoding(); null === $encoding && $encoding = p\Iconv::$internalEncoding; mb_internal_encoding($encoding); $decoded = mb_decode_mimeheader($string); mb_internal_encoding($currentMbEncoding); return $decoded; } - } -} else { - if (!function_exists('iconv_strlen')) { - function iconv_strlen(?string $string, ?string $encoding = null): int|false { return p\Iconv::iconv_strlen((string) $string, $encoding); } - } - - if (!function_exists('iconv_strpos')) { - function iconv_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Iconv::iconv_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } - } - if (!function_exists('iconv_strrpos')) { - function iconv_strrpos(?string $haystack, ?string $needle, ?string $encoding = null): int|false { return p\Iconv::iconv_strrpos((string) $haystack, (string) $needle, $encoding); } - } - if (!function_exists('iconv_substr')) { - function iconv_substr(?string $string, ?int $offset, ?int $length = null, ?string $encoding = null): string|false { return p\Iconv::iconv_substr((string) $string, (string) $offset, $length, $encoding); } - } - if (!function_exists('iconv_mime_decode')) { - function iconv_mime_decode(?string $string, ?int $mode = 0, ?string $encoding = null): string|false { return p\Iconv::iconv_mime_decode((string) $string, (int) $mode, $encoding); } - } -} diff --git a/src/Iconv/composer.json b/src/Iconv/composer.json index af0b17396..13b011a26 100644 --- a/src/Iconv/composer.json +++ b/src/Iconv/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "provide": { "ext-iconv": "*" diff --git a/src/Intl/Grapheme/Grapheme.php b/src/Intl/Grapheme/Grapheme.php index 5373f1685..130d11f29 100644 --- a/src/Intl/Grapheme/Grapheme.php +++ b/src/Intl/Grapheme/Grapheme.php @@ -67,10 +67,6 @@ public static function grapheme_extract($s, $size, $type = \GRAPHEME_EXTR_COUNT, $start = (int) $start; if (\GRAPHEME_EXTR_COUNT !== $type && \GRAPHEME_EXTR_MAXBYTES !== $type && \GRAPHEME_EXTR_MAXCHARS !== $type) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS'); } @@ -133,14 +129,10 @@ public static function grapheme_substr($s, $start, $len = null) $start += $slen; } if (0 > $start) { - if (\PHP_VERSION_ID < 80000) { - return false; - } - $start = 0; } if ($start >= $slen) { - return \PHP_VERSION_ID >= 80000 ? '' : false; + return ''; } $rem = $slen - $start; @@ -152,7 +144,7 @@ public static function grapheme_substr($s, $start, $len = null) return ''; } if (0 > $len) { - return \PHP_VERSION_ID >= 80000 ? '' : false; + return ''; } if ($len > $rem) { $len = $rem; @@ -194,7 +186,7 @@ public static function grapheme_strstr($s, $needle, $beforeNeedle = false) private static function grapheme_position($s, $needle, $offset, $mode) { $needle = (string) $needle; - if (80000 > \PHP_VERSION_ID && !preg_match('/./us', $needle)) { + if (!preg_match('/./us', $needle)) { return false; } $s = (string) $s; diff --git a/src/Intl/Grapheme/bootstrap.php b/src/Intl/Grapheme/bootstrap.php index a9ea03c7e..18ad15530 100644 --- a/src/Intl/Grapheme/bootstrap.php +++ b/src/Intl/Grapheme/bootstrap.php @@ -15,10 +15,6 @@ return; } -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!defined('GRAPHEME_EXTR_COUNT')) { define('GRAPHEME_EXTR_COUNT', 0); } @@ -30,29 +26,29 @@ } if (!function_exists('grapheme_extract')) { - function grapheme_extract($haystack, $size, $type = 0, $start = 0, &$next = 0) { return p\Grapheme::grapheme_extract($haystack, $size, $type, $start, $next); } + function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); } } if (!function_exists('grapheme_stripos')) { - function grapheme_stripos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_stripos($haystack, $needle, $offset); } + function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); } } if (!function_exists('grapheme_stristr')) { - function grapheme_stristr($haystack, $needle, $beforeNeedle = false) { return p\Grapheme::grapheme_stristr($haystack, $needle, $beforeNeedle); } + function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } } if (!function_exists('grapheme_strlen')) { - function grapheme_strlen($input) { return p\Grapheme::grapheme_strlen($input); } + function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); } } if (!function_exists('grapheme_strpos')) { - function grapheme_strpos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strpos($haystack, $needle, $offset); } + function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); } } if (!function_exists('grapheme_strripos')) { - function grapheme_strripos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strripos($haystack, $needle, $offset); } + function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); } } if (!function_exists('grapheme_strrpos')) { - function grapheme_strrpos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strrpos($haystack, $needle, $offset); } + function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); } } if (!function_exists('grapheme_strstr')) { - function grapheme_strstr($haystack, $needle, $beforeNeedle = false) { return p\Grapheme::grapheme_strstr($haystack, $needle, $beforeNeedle); } + function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } } if (!function_exists('grapheme_substr')) { - function grapheme_substr($string, $offset, $length = null) { return p\Grapheme::grapheme_substr($string, $offset, $length); } + function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); } } diff --git a/src/Intl/Grapheme/bootstrap80.php b/src/Intl/Grapheme/bootstrap80.php deleted file mode 100644 index b8c078677..000000000 --- a/src/Intl/Grapheme/bootstrap80.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Intl\Grapheme as p; - -if (!defined('GRAPHEME_EXTR_COUNT')) { - define('GRAPHEME_EXTR_COUNT', 0); -} -if (!defined('GRAPHEME_EXTR_MAXBYTES')) { - define('GRAPHEME_EXTR_MAXBYTES', 1); -} -if (!defined('GRAPHEME_EXTR_MAXCHARS')) { - define('GRAPHEME_EXTR_MAXCHARS', 2); -} - -if (!function_exists('grapheme_extract')) { - function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); } -} -if (!function_exists('grapheme_stripos')) { - function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); } -} -if (!function_exists('grapheme_stristr')) { - function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } -} -if (!function_exists('grapheme_strlen')) { - function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); } -} -if (!function_exists('grapheme_strpos')) { - function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); } -} -if (!function_exists('grapheme_strripos')) { - function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); } -} -if (!function_exists('grapheme_strrpos')) { - function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); } -} -if (!function_exists('grapheme_strstr')) { - function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } -} -if (!function_exists('grapheme_substr')) { - function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); } -} diff --git a/src/Intl/Grapheme/composer.json b/src/Intl/Grapheme/composer.json index 0eea417d7..7bb09abad 100644 --- a/src/Intl/Grapheme/composer.json +++ b/src/Intl/Grapheme/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Intl\\Grapheme\\": "" }, diff --git a/src/Intl/Icu/IntlDateFormatter.php b/src/Intl/Icu/IntlDateFormatter.php index b2674f906..804e1a7f7 100644 --- a/src/Intl/Icu/IntlDateFormatter.php +++ b/src/Intl/Icu/IntlDateFormatter.php @@ -152,14 +152,12 @@ public function __construct(?string $locale, ?int $dateType, ?int $timeType, $ti throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported'); } - if (\PHP_VERSION_ID >= 80100) { - if (null === $dateType) { - @trigger_error('Passing null to parameter #2 ($dateType) of type int is deprecated', \E_USER_DEPRECATED); - } + if (null === $dateType) { + @trigger_error('Passing null to parameter #2 ($dateType) of type int is deprecated', \E_USER_DEPRECATED); + } - if (null === $timeType) { - @trigger_error('Passing null to parameter #3 ($timeType) of type int is deprecated', \E_USER_DEPRECATED); - } + if (null === $timeType) { + @trigger_error('Passing null to parameter #3 ($timeType) of type int is deprecated', \E_USER_DEPRECATED); } $this->dateType = $dateType ?? self::FULL; diff --git a/src/Intl/Icu/NumberFormatter.php b/src/Intl/Icu/NumberFormatter.php index 5b247066c..8adfc5dce 100644 --- a/src/Intl/Icu/NumberFormatter.php +++ b/src/Intl/Icu/NumberFormatter.php @@ -351,13 +351,7 @@ public function format($num, int $type = self::TYPE_DEFAULT) { // The original NumberFormatter does not support this format type if (self::TYPE_CURRENCY === $type) { - if (\PHP_VERSION_ID >= 80000) { - throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type)); - } - - trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING); - - return false; + throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type)); } if (self::CURRENCY === $this->style) { @@ -495,13 +489,7 @@ public function parseCurrency(string $string, &$currency, &$offset = null) public function parse(string $string, int $type = self::TYPE_DOUBLE, &$offset = null) { if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) { - if (\PHP_VERSION_ID >= 80000) { - throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type)); - } - - trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING); - - return false; + throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type)); } // Any invalid number at the end of the string is removed. diff --git a/src/Intl/Icu/bootstrap.php b/src/Intl/Icu/bootstrap.php index 77d754379..2709693f3 100644 --- a/src/Intl/Icu/bootstrap.php +++ b/src/Intl/Icu/bootstrap.php @@ -15,19 +15,15 @@ return; } -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!function_exists('intl_is_failure')) { - function intl_is_failure($errorCode) { return p\Icu::isFailure($errorCode); } + function intl_is_failure(?int $errorCode): bool { return p\Icu::isFailure((int) $errorCode); } } if (!function_exists('intl_get_error_code')) { - function intl_get_error_code() { return p\Icu::getErrorCode(); } + function intl_get_error_code(): int { return p\Icu::getErrorCode(); } } if (!function_exists('intl_get_error_message')) { - function intl_get_error_message() { return p\Icu::getErrorMessage(); } + function intl_get_error_message(): string { return p\Icu::getErrorMessage(); } } if (!function_exists('intl_error_name')) { - function intl_error_name($errorCode) { return p\Icu::getErrorName($errorCode); } + function intl_error_name(?int $errorCode): string { return p\Icu::getErrorName((int) $errorCode); } } diff --git a/src/Intl/Icu/bootstrap80.php b/src/Intl/Icu/bootstrap80.php deleted file mode 100644 index ee1653a38..000000000 --- a/src/Intl/Icu/bootstrap80.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Intl\Icu as p; - -if (!function_exists('intl_is_failure')) { - function intl_is_failure(?int $errorCode): bool { return p\Icu::isFailure((int) $errorCode); } -} -if (!function_exists('intl_get_error_code')) { - function intl_get_error_code(): int { return p\Icu::getErrorCode(); } -} -if (!function_exists('intl_get_error_message')) { - function intl_get_error_message(): string { return p\Icu::getErrorMessage(); } -} -if (!function_exists('intl_error_name')) { - function intl_error_name(?int $errorCode): string { return p\Icu::getErrorName((int) $errorCode); } -} diff --git a/src/Intl/Icu/composer.json b/src/Intl/Icu/composer.json index 33c74ab91..319806655 100644 --- a/src/Intl/Icu/composer.json +++ b/src/Intl/Icu/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "files": [ "bootstrap.php" ], diff --git a/src/Intl/Idn/bootstrap.php b/src/Intl/Idn/bootstrap.php index 57c78356c..8c2164604 100644 --- a/src/Intl/Idn/bootstrap.php +++ b/src/Intl/Idn/bootstrap.php @@ -15,10 +15,6 @@ return; } -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!defined('U_IDNA_PROHIBITED_ERROR')) { define('U_IDNA_PROHIBITED_ERROR', 66560); } @@ -82,9 +78,6 @@ if (!defined('IDNA_NONTRANSITIONAL_TO_UNICODE')) { define('IDNA_NONTRANSITIONAL_TO_UNICODE', 32); } -if (!defined('INTL_IDNA_VARIANT_2003')) { - define('INTL_IDNA_VARIANT_2003', 0); -} if (!defined('INTL_IDNA_VARIANT_UTS46')) { define('INTL_IDNA_VARIANT_UTS46', 1); } @@ -128,18 +121,9 @@ define('IDNA_ERROR_CONTEXTJ', 4096); } -if (\PHP_VERSION_ID < 70400) { - if (!function_exists('idn_to_ascii')) { - function idn_to_ascii($domain, $flags = 0, $variant = \INTL_IDNA_VARIANT_2003, &$idna_info = null) { return p\Idn::idn_to_ascii($domain, $flags, $variant, $idna_info); } - } - if (!function_exists('idn_to_utf8')) { - function idn_to_utf8($domain, $flags = 0, $variant = \INTL_IDNA_VARIANT_2003, &$idna_info = null) { return p\Idn::idn_to_utf8($domain, $flags, $variant, $idna_info); } - } -} else { - if (!function_exists('idn_to_ascii')) { - function idn_to_ascii($domain, $flags = 0, $variant = \INTL_IDNA_VARIANT_UTS46, &$idna_info = null) { return p\Idn::idn_to_ascii($domain, $flags, $variant, $idna_info); } - } - if (!function_exists('idn_to_utf8')) { - function idn_to_utf8($domain, $flags = 0, $variant = \INTL_IDNA_VARIANT_UTS46, &$idna_info = null) { return p\Idn::idn_to_utf8($domain, $flags, $variant, $idna_info); } - } +if (!function_exists('idn_to_ascii')) { + function idn_to_ascii(?string $domain, ?int $flags = IDNA_DEFAULT, ?int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_ascii((string) $domain, (int) $flags, (int) $variant, $idna_info); } +} +if (!function_exists('idn_to_utf8')) { + function idn_to_utf8(?string $domain, ?int $flags = IDNA_DEFAULT, ?int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_utf8((string) $domain, (int) $flags, (int) $variant, $idna_info); } } diff --git a/src/Intl/Idn/bootstrap80.php b/src/Intl/Idn/bootstrap80.php deleted file mode 100644 index a62c2d69b..000000000 --- a/src/Intl/Idn/bootstrap80.php +++ /dev/null @@ -1,125 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Intl\Idn as p; - -if (!defined('U_IDNA_PROHIBITED_ERROR')) { - define('U_IDNA_PROHIBITED_ERROR', 66560); -} -if (!defined('U_IDNA_ERROR_START')) { - define('U_IDNA_ERROR_START', 66560); -} -if (!defined('U_IDNA_UNASSIGNED_ERROR')) { - define('U_IDNA_UNASSIGNED_ERROR', 66561); -} -if (!defined('U_IDNA_CHECK_BIDI_ERROR')) { - define('U_IDNA_CHECK_BIDI_ERROR', 66562); -} -if (!defined('U_IDNA_STD3_ASCII_RULES_ERROR')) { - define('U_IDNA_STD3_ASCII_RULES_ERROR', 66563); -} -if (!defined('U_IDNA_ACE_PREFIX_ERROR')) { - define('U_IDNA_ACE_PREFIX_ERROR', 66564); -} -if (!defined('U_IDNA_VERIFICATION_ERROR')) { - define('U_IDNA_VERIFICATION_ERROR', 66565); -} -if (!defined('U_IDNA_LABEL_TOO_LONG_ERROR')) { - define('U_IDNA_LABEL_TOO_LONG_ERROR', 66566); -} -if (!defined('U_IDNA_ZERO_LENGTH_LABEL_ERROR')) { - define('U_IDNA_ZERO_LENGTH_LABEL_ERROR', 66567); -} -if (!defined('U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR')) { - define('U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR', 66568); -} -if (!defined('U_IDNA_ERROR_LIMIT')) { - define('U_IDNA_ERROR_LIMIT', 66569); -} -if (!defined('U_STRINGPREP_PROHIBITED_ERROR')) { - define('U_STRINGPREP_PROHIBITED_ERROR', 66560); -} -if (!defined('U_STRINGPREP_UNASSIGNED_ERROR')) { - define('U_STRINGPREP_UNASSIGNED_ERROR', 66561); -} -if (!defined('U_STRINGPREP_CHECK_BIDI_ERROR')) { - define('U_STRINGPREP_CHECK_BIDI_ERROR', 66562); -} -if (!defined('IDNA_DEFAULT')) { - define('IDNA_DEFAULT', 0); -} -if (!defined('IDNA_ALLOW_UNASSIGNED')) { - define('IDNA_ALLOW_UNASSIGNED', 1); -} -if (!defined('IDNA_USE_STD3_RULES')) { - define('IDNA_USE_STD3_RULES', 2); -} -if (!defined('IDNA_CHECK_BIDI')) { - define('IDNA_CHECK_BIDI', 4); -} -if (!defined('IDNA_CHECK_CONTEXTJ')) { - define('IDNA_CHECK_CONTEXTJ', 8); -} -if (!defined('IDNA_NONTRANSITIONAL_TO_ASCII')) { - define('IDNA_NONTRANSITIONAL_TO_ASCII', 16); -} -if (!defined('IDNA_NONTRANSITIONAL_TO_UNICODE')) { - define('IDNA_NONTRANSITIONAL_TO_UNICODE', 32); -} -if (!defined('INTL_IDNA_VARIANT_UTS46')) { - define('INTL_IDNA_VARIANT_UTS46', 1); -} -if (!defined('IDNA_ERROR_EMPTY_LABEL')) { - define('IDNA_ERROR_EMPTY_LABEL', 1); -} -if (!defined('IDNA_ERROR_LABEL_TOO_LONG')) { - define('IDNA_ERROR_LABEL_TOO_LONG', 2); -} -if (!defined('IDNA_ERROR_DOMAIN_NAME_TOO_LONG')) { - define('IDNA_ERROR_DOMAIN_NAME_TOO_LONG', 4); -} -if (!defined('IDNA_ERROR_LEADING_HYPHEN')) { - define('IDNA_ERROR_LEADING_HYPHEN', 8); -} -if (!defined('IDNA_ERROR_TRAILING_HYPHEN')) { - define('IDNA_ERROR_TRAILING_HYPHEN', 16); -} -if (!defined('IDNA_ERROR_HYPHEN_3_4')) { - define('IDNA_ERROR_HYPHEN_3_4', 32); -} -if (!defined('IDNA_ERROR_LEADING_COMBINING_MARK')) { - define('IDNA_ERROR_LEADING_COMBINING_MARK', 64); -} -if (!defined('IDNA_ERROR_DISALLOWED')) { - define('IDNA_ERROR_DISALLOWED', 128); -} -if (!defined('IDNA_ERROR_PUNYCODE')) { - define('IDNA_ERROR_PUNYCODE', 256); -} -if (!defined('IDNA_ERROR_LABEL_HAS_DOT')) { - define('IDNA_ERROR_LABEL_HAS_DOT', 512); -} -if (!defined('IDNA_ERROR_INVALID_ACE_LABEL')) { - define('IDNA_ERROR_INVALID_ACE_LABEL', 1024); -} -if (!defined('IDNA_ERROR_BIDI')) { - define('IDNA_ERROR_BIDI', 2048); -} -if (!defined('IDNA_ERROR_CONTEXTJ')) { - define('IDNA_ERROR_CONTEXTJ', 4096); -} - -if (!function_exists('idn_to_ascii')) { - function idn_to_ascii(?string $domain, ?int $flags = IDNA_DEFAULT, ?int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_ascii((string) $domain, (int) $flags, (int) $variant, $idna_info); } -} -if (!function_exists('idn_to_utf8')) { - function idn_to_utf8(?string $domain, ?int $flags = IDNA_DEFAULT, ?int $variant = INTL_IDNA_VARIANT_UTS46, &$idna_info = null): string|false { return p\Idn::idn_to_utf8((string) $domain, (int) $flags, (int) $variant, $idna_info); } -} diff --git a/src/Intl/Idn/composer.json b/src/Intl/Idn/composer.json index 760debcd2..742f9346b 100644 --- a/src/Intl/Idn/composer.json +++ b/src/Intl/Idn/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=7.2", + "php": ">=8.1", "symfony/polyfill-intl-normalizer": "^1.10" }, "autoload": { diff --git a/src/Intl/MessageFormatter/composer.json b/src/Intl/MessageFormatter/composer.json index bac270a24..507ae5a0a 100644 --- a/src/Intl/MessageFormatter/composer.json +++ b/src/Intl/MessageFormatter/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Intl\\MessageFormatter\\": "" }, diff --git a/src/Intl/Normalizer/Normalizer.php b/src/Intl/Normalizer/Normalizer.php index 81704ab37..b1a6a2cdc 100644 --- a/src/Intl/Normalizer/Normalizer.php +++ b/src/Intl/Normalizer/Normalizer.php @@ -70,10 +70,6 @@ public static function normalize(string $s, int $form = self::FORM_C) return $s; } - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form'); } diff --git a/src/Intl/Normalizer/bootstrap.php b/src/Intl/Normalizer/bootstrap.php index 3608e5c05..e36d1a947 100644 --- a/src/Intl/Normalizer/bootstrap.php +++ b/src/Intl/Normalizer/bootstrap.php @@ -11,13 +11,9 @@ use Symfony\Polyfill\Intl\Normalizer as p; -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!function_exists('normalizer_is_normalized')) { - function normalizer_is_normalized($string, $form = p\Normalizer::FORM_C) { return p\Normalizer::isNormalized($string, $form); } + function normalizer_is_normalized(?string $string, ?int $form = p\Normalizer::FORM_C): bool { return p\Normalizer::isNormalized((string) $string, (int) $form); } } if (!function_exists('normalizer_normalize')) { - function normalizer_normalize($string, $form = p\Normalizer::FORM_C) { return p\Normalizer::normalize($string, $form); } + function normalizer_normalize(?string $string, ?int $form = p\Normalizer::FORM_C): string|false { return p\Normalizer::normalize((string) $string, (int) $form); } } diff --git a/src/Intl/Normalizer/bootstrap80.php b/src/Intl/Normalizer/bootstrap80.php deleted file mode 100644 index e36d1a947..000000000 --- a/src/Intl/Normalizer/bootstrap80.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Intl\Normalizer as p; - -if (!function_exists('normalizer_is_normalized')) { - function normalizer_is_normalized(?string $string, ?int $form = p\Normalizer::FORM_C): bool { return p\Normalizer::isNormalized((string) $string, (int) $form); } -} -if (!function_exists('normalizer_normalize')) { - function normalizer_normalize(?string $string, ?int $form = p\Normalizer::FORM_C): string|false { return p\Normalizer::normalize((string) $string, (int) $form); } -} diff --git a/src/Intl/Normalizer/composer.json b/src/Intl/Normalizer/composer.json index 9bd04e887..2882f63d2 100644 --- a/src/Intl/Normalizer/composer.json +++ b/src/Intl/Normalizer/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Intl\\Normalizer\\": "" }, diff --git a/src/Mbstring/Mbstring.php b/src/Mbstring/Mbstring.php index 3d45c9d9a..fb21032a5 100644 --- a/src/Mbstring/Mbstring.php +++ b/src/Mbstring/Mbstring.php @@ -160,7 +160,7 @@ public static function mb_decode_numericentity($s, $convmap, $encoding = null) return null; } - if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { + if (!\is_array($convmap)) { return false; } @@ -220,7 +220,7 @@ public static function mb_encode_numericentity($s, $convmap, $encoding = null, $ return null; } - if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { + if (!\is_array($convmap)) { return false; } @@ -378,10 +378,6 @@ public static function mb_internal_encoding($encoding = null) return true; } - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError(sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding)); } @@ -399,10 +395,6 @@ public static function mb_language($lang = null) return true; } - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError(sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang)); } @@ -531,12 +523,6 @@ public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = nu $needle = (string) $needle; if ('' === $needle) { - if (80000 > \PHP_VERSION_ID) { - trigger_error(__METHOD__.': Empty delimiter', \E_USER_WARNING); - - return false; - } - return 0; } @@ -563,7 +549,7 @@ public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = n } } - $pos = '' !== $needle || 80000 > \PHP_VERSION_ID + $pos = '' !== $needle ? iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding); @@ -579,12 +565,6 @@ public static function mb_str_split($string, $split_length = 1, $encoding = null } if (1 > $split_length = (int) $split_length) { - if (80000 > \PHP_VERSION_ID) { - trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING); - - return false; - } - throw new \ValueError('Argument #2 ($length) must be greater than 0'); } @@ -631,9 +611,6 @@ public static function mb_substitute_character($c = null) if (0 === strcasecmp($c, 'none')) { return true; } - if (80000 > \PHP_VERSION_ID) { - return false; - } if (\is_int($c) || 'long' === $c || 'entity' === $c) { return false; } diff --git a/src/Mbstring/bootstrap.php b/src/Mbstring/bootstrap.php index ff51ae079..5236e6dcc 100644 --- a/src/Mbstring/bootstrap.php +++ b/src/Mbstring/bootstrap.php @@ -11,125 +11,121 @@ use Symfony\Polyfill\Mbstring as p; -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!function_exists('mb_convert_encoding')) { - function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } + function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } } if (!function_exists('mb_decode_mimeheader')) { - function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } + function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); } } if (!function_exists('mb_encode_mimeheader')) { - function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } + function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); } } if (!function_exists('mb_decode_numericentity')) { - function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } + function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); } } if (!function_exists('mb_encode_numericentity')) { - function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } + function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); } } if (!function_exists('mb_convert_case')) { - function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } + function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); } } if (!function_exists('mb_internal_encoding')) { - function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } + function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } } if (!function_exists('mb_language')) { - function mb_language($language = null) { return p\Mbstring::mb_language($language); } + function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); } } if (!function_exists('mb_list_encodings')) { - function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } + function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } } if (!function_exists('mb_encoding_aliases')) { - function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } + function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); } } if (!function_exists('mb_check_encoding')) { - function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } + function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } } if (!function_exists('mb_detect_encoding')) { - function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } + function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } } if (!function_exists('mb_detect_order')) { - function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } + function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } } if (!function_exists('mb_parse_str')) { - function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } + function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; } } if (!function_exists('mb_strlen')) { - function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } + function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); } } if (!function_exists('mb_strpos')) { - function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } + function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } } if (!function_exists('mb_strtolower')) { - function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } + function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); } } if (!function_exists('mb_strtoupper')) { - function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } + function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); } } if (!function_exists('mb_substitute_character')) { - function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } + function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } } if (!function_exists('mb_substr')) { - function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } + function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); } } if (!function_exists('mb_stripos')) { - function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } + function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } } if (!function_exists('mb_stristr')) { - function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } + function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } } if (!function_exists('mb_strrchr')) { - function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } + function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } } if (!function_exists('mb_strrichr')) { - function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } + function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } } if (!function_exists('mb_strripos')) { - function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } + function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } } if (!function_exists('mb_strrpos')) { - function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } + function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } } if (!function_exists('mb_strstr')) { - function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } + function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } } if (!function_exists('mb_get_info')) { - function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } + function mb_get_info(?string $type = 'all'): array|string|int|false|null { return p\Mbstring::mb_get_info((string) $type); } } if (!function_exists('mb_http_output')) { - function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } + function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } } if (!function_exists('mb_strwidth')) { - function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } + function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); } } if (!function_exists('mb_substr_count')) { - function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } + function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); } } if (!function_exists('mb_output_handler')) { - function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } + function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); } } if (!function_exists('mb_http_input')) { - function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } + function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } } if (!function_exists('mb_convert_variables')) { - function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } + function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } } if (!function_exists('mb_ord')) { - function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } + function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); } } if (!function_exists('mb_chr')) { - function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } + function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } } if (!function_exists('mb_scrub')) { - function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } + function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); } } if (!function_exists('mb_str_split')) { - function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } + function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); } } if (!function_exists('mb_str_pad')) { @@ -156,7 +152,6 @@ function mb_ltrim(string $string, ?string $characters = null, ?string $encoding function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_rtrim($string, $characters, $encoding); } } - if (extension_loaded('mbstring')) { return; } diff --git a/src/Mbstring/bootstrap80.php b/src/Mbstring/bootstrap80.php deleted file mode 100644 index 5236e6dcc..000000000 --- a/src/Mbstring/bootstrap80.php +++ /dev/null @@ -1,167 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Mbstring as p; - -if (!function_exists('mb_convert_encoding')) { - function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } -} -if (!function_exists('mb_decode_mimeheader')) { - function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); } -} -if (!function_exists('mb_encode_mimeheader')) { - function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); } -} -if (!function_exists('mb_decode_numericentity')) { - function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); } -} -if (!function_exists('mb_encode_numericentity')) { - function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); } -} -if (!function_exists('mb_convert_case')) { - function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); } -} -if (!function_exists('mb_internal_encoding')) { - function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } -} -if (!function_exists('mb_language')) { - function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); } -} -if (!function_exists('mb_list_encodings')) { - function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } -} -if (!function_exists('mb_encoding_aliases')) { - function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); } -} -if (!function_exists('mb_check_encoding')) { - function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } -} -if (!function_exists('mb_detect_encoding')) { - function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } -} -if (!function_exists('mb_detect_order')) { - function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } -} -if (!function_exists('mb_parse_str')) { - function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; } -} -if (!function_exists('mb_strlen')) { - function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); } -} -if (!function_exists('mb_strpos')) { - function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } -} -if (!function_exists('mb_strtolower')) { - function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); } -} -if (!function_exists('mb_strtoupper')) { - function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); } -} -if (!function_exists('mb_substitute_character')) { - function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } -} -if (!function_exists('mb_substr')) { - function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); } -} -if (!function_exists('mb_stripos')) { - function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } -} -if (!function_exists('mb_stristr')) { - function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } -} -if (!function_exists('mb_strrchr')) { - function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } -} -if (!function_exists('mb_strrichr')) { - function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } -} -if (!function_exists('mb_strripos')) { - function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } -} -if (!function_exists('mb_strrpos')) { - function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } -} -if (!function_exists('mb_strstr')) { - function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } -} -if (!function_exists('mb_get_info')) { - function mb_get_info(?string $type = 'all'): array|string|int|false|null { return p\Mbstring::mb_get_info((string) $type); } -} -if (!function_exists('mb_http_output')) { - function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } -} -if (!function_exists('mb_strwidth')) { - function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); } -} -if (!function_exists('mb_substr_count')) { - function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); } -} -if (!function_exists('mb_output_handler')) { - function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); } -} -if (!function_exists('mb_http_input')) { - function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } -} - -if (!function_exists('mb_convert_variables')) { - function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } -} - -if (!function_exists('mb_ord')) { - function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); } -} -if (!function_exists('mb_chr')) { - function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } -} -if (!function_exists('mb_scrub')) { - function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); } -} -if (!function_exists('mb_str_split')) { - function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); } -} - -if (!function_exists('mb_str_pad')) { - function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); } -} - -if (!function_exists('mb_ucfirst')) { - function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); } -} - -if (!function_exists('mb_lcfirst')) { - function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); } -} - -if (!function_exists('mb_trim')) { - function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_trim($string, $characters, $encoding); } -} - -if (!function_exists('mb_ltrim')) { - function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_ltrim($string, $characters, $encoding); } -} - -if (!function_exists('mb_rtrim')) { - function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_rtrim($string, $characters, $encoding); } -} - -if (extension_loaded('mbstring')) { - return; -} - -if (!defined('MB_CASE_UPPER')) { - define('MB_CASE_UPPER', 0); -} -if (!defined('MB_CASE_LOWER')) { - define('MB_CASE_LOWER', 1); -} -if (!defined('MB_CASE_TITLE')) { - define('MB_CASE_TITLE', 2); -} diff --git a/src/Mbstring/composer.json b/src/Mbstring/composer.json index 4ed241a33..d568860d2 100644 --- a/src/Mbstring/composer.json +++ b/src/Mbstring/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "provide": { "ext-mbstring": "*" diff --git a/src/Php73/Php73.php b/src/Php73/Php73.php deleted file mode 100644 index 65c35a6a1..000000000 --- a/src/Php73/Php73.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Php73; - -/** - * @author Gabriel Caruso - * @author Ion Bazan - * - * @internal - */ -final class Php73 -{ - public static $startAt = 1533462603; - - /** - * @param bool $asNum - * - * @return array|float|int - */ - public static function hrtime($asNum = false) - { - $ns = microtime(false); - $s = substr($ns, 11) - self::$startAt; - $ns = 1E9 * (float) $ns; - - if ($asNum) { - $ns += $s * 1E9; - - return \PHP_INT_SIZE === 4 ? $ns : (int) $ns; - } - - return [$s, (int) $ns]; - } -} diff --git a/src/Php73/Resources/stubs/JsonException.php b/src/Php73/Resources/stubs/JsonException.php deleted file mode 100644 index f06d6c269..000000000 --- a/src/Php73/Resources/stubs/JsonException.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID < 70300) { - class JsonException extends Exception - { - } -} diff --git a/src/Php73/bootstrap.php b/src/Php73/bootstrap.php deleted file mode 100644 index d6b215382..000000000 --- a/src/Php73/bootstrap.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Php73 as p; - -if (\PHP_VERSION_ID >= 70300) { - return; -} - -if (!function_exists('is_countable')) { - function is_countable($value) { return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } -} -if (!function_exists('hrtime')) { - require_once __DIR__.'/Php73.php'; - p\Php73::$startAt = (int) microtime(true); - function hrtime($as_number = false) { return p\Php73::hrtime($as_number); } -} -if (!function_exists('array_key_first')) { - function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } } -} -if (!function_exists('array_key_last')) { - function array_key_last(array $array) { return key(array_slice($array, -1, 1, true)); } -} diff --git a/src/Php73/composer.json b/src/Php73/composer.json index 09d98cb87..2d0266317 100644 --- a/src/Php73/composer.json +++ b/src/Php73/composer.json @@ -1,6 +1,6 @@ { "name": "symfony/polyfill-php73", - "type": "library", + "type": "metapackage", "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", "keywords": ["polyfill", "shim", "compatibility", "portable"], "homepage": "https://symfony.com", @@ -16,12 +16,7 @@ } ], "require": { - "php": ">=7.2" - }, - "autoload": { - "psr-4": { "Symfony\\Polyfill\\Php73\\": "" }, - "files": [ "bootstrap.php" ], - "classmap": [ "Resources/stubs" ] + "php": ">=7.3" }, "minimum-stability": "dev", "extra": { diff --git a/src/Php74/Php74.php b/src/Php74/Php74.php deleted file mode 100644 index f372c450c..000000000 --- a/src/Php74/Php74.php +++ /dev/null @@ -1,94 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Php74; - -/** - * @author Ion Bazan - * - * @internal - */ -final class Php74 -{ - public static function get_mangled_object_vars($obj) - { - if (!\is_object($obj)) { - trigger_error('get_mangled_object_vars() expects parameter 1 to be object, '.\gettype($obj).' given', \E_USER_WARNING); - - return null; - } - - if ($obj instanceof \ArrayIterator || $obj instanceof \ArrayObject) { - $reflector = new \ReflectionClass($obj instanceof \ArrayIterator ? 'ArrayIterator' : 'ArrayObject'); - $flags = $reflector->getMethod('getFlags')->invoke($obj); - $reflector = $reflector->getMethod('setFlags'); - - $reflector->invoke($obj, ($flags & \ArrayObject::STD_PROP_LIST) ? 0 : \ArrayObject::STD_PROP_LIST); - $arr = (array) $obj; - $reflector->invoke($obj, $flags); - } else { - $arr = (array) $obj; - } - - return array_combine(array_keys($arr), array_values($arr)); - } - - public static function mb_str_split($string, $split_length = 1, $encoding = null) - { - if (null !== $string && !\is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) { - trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', \E_USER_WARNING); - - return null; - } - - if (1 > $split_length = (int) $split_length) { - trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING); - - return false; - } - - if (null === $encoding) { - $encoding = mb_internal_encoding(); - } - - if ('UTF-8' === $encoding || \in_array(strtoupper($encoding), ['UTF-8', 'UTF8'], true)) { - return preg_split("/(.{{$split_length}})/u", $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY); - } - - $result = []; - $length = mb_strlen($string, $encoding); - - for ($i = 0; $i < $length; $i += $split_length) { - $result[] = mb_substr($string, $i, $split_length, $encoding); - } - - return $result; - } - - public static function password_algos() - { - $algos = []; - - if (\defined('PASSWORD_BCRYPT')) { - $algos[] = \PASSWORD_BCRYPT; - } - - if (\defined('PASSWORD_ARGON2I')) { - $algos[] = \PASSWORD_ARGON2I; - } - - if (\defined('PASSWORD_ARGON2ID')) { - $algos[] = \PASSWORD_ARGON2ID; - } - - return $algos; - } -} diff --git a/src/Php74/bootstrap.php b/src/Php74/bootstrap.php deleted file mode 100644 index c894d99f3..000000000 --- a/src/Php74/bootstrap.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Php74 as p; - -if (\PHP_VERSION_ID >= 70400) { - return; -} - -if (!function_exists('get_mangled_object_vars')) { - function get_mangled_object_vars($object) { return p\Php74::get_mangled_object_vars($object); } -} -if (!function_exists('password_algos')) { - function password_algos() { return p\Php74::password_algos(); } -} -if (extension_loaded('mbstring')) { - if (!function_exists('mb_str_split')) { - function mb_str_split($string, $length = 1, $encoding = null) { return p\Php74::mb_str_split($string, $length, $encoding); } - } -} diff --git a/src/Php74/composer.json b/src/Php74/composer.json index ede769e9a..fc8df6f05 100644 --- a/src/Php74/composer.json +++ b/src/Php74/composer.json @@ -1,6 +1,6 @@ { "name": "symfony/polyfill-php74", - "type": "library", + "type": "metapackage", "description": "Symfony polyfill backporting some PHP 7.4+ features to lower PHP versions", "keywords": ["polyfill", "shim", "compatibility", "portable"], "homepage": "https://symfony.com", @@ -20,11 +20,7 @@ } ], "require": { - "php": ">=7.2" - }, - "autoload": { - "psr-4": { "Symfony\\Polyfill\\Php74\\": "" }, - "files": [ "bootstrap.php" ] + "php": ">=7.4" }, "minimum-stability": "dev", "extra": { diff --git a/src/Php80/Php80.php b/src/Php80/Php80.php deleted file mode 100644 index 362dd1a95..000000000 --- a/src/Php80/Php80.php +++ /dev/null @@ -1,115 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Php80; - -/** - * @author Ion Bazan - * @author Nico Oelgart - * @author Nicolas Grekas - * - * @internal - */ -final class Php80 -{ - public static function fdiv(float $dividend, float $divisor): float - { - return @($dividend / $divisor); - } - - public static function get_debug_type($value): string - { - switch (true) { - case null === $value: return 'null'; - case \is_bool($value): return 'bool'; - case \is_string($value): return 'string'; - case \is_array($value): return 'array'; - case \is_int($value): return 'int'; - case \is_float($value): return 'float'; - case \is_object($value): break; - case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; - default: - if (null === $type = @get_resource_type($value)) { - return 'unknown'; - } - - if ('Unknown' === $type) { - $type = 'closed'; - } - - return "resource ($type)"; - } - - $class = \get_class($value); - - if (false === strpos($class, '@')) { - return $class; - } - - return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; - } - - public static function get_resource_id($res): int - { - if (!\is_resource($res) && null === @get_resource_type($res)) { - throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); - } - - return (int) $res; - } - - public static function preg_last_error_msg(): string - { - switch (preg_last_error()) { - case \PREG_INTERNAL_ERROR: - return 'Internal error'; - case \PREG_BAD_UTF8_ERROR: - return 'Malformed UTF-8 characters, possibly incorrectly encoded'; - case \PREG_BAD_UTF8_OFFSET_ERROR: - return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; - case \PREG_BACKTRACK_LIMIT_ERROR: - return 'Backtrack limit exhausted'; - case \PREG_RECURSION_LIMIT_ERROR: - return 'Recursion limit exhausted'; - case \PREG_JIT_STACKLIMIT_ERROR: - return 'JIT stack limit exhausted'; - case \PREG_NO_ERROR: - return 'No error'; - default: - return 'Unknown error'; - } - } - - public static function str_contains(string $haystack, string $needle): bool - { - return '' === $needle || false !== strpos($haystack, $needle); - } - - public static function str_starts_with(string $haystack, string $needle): bool - { - return 0 === strncmp($haystack, $needle, \strlen($needle)); - } - - public static function str_ends_with(string $haystack, string $needle): bool - { - if ('' === $needle || $needle === $haystack) { - return true; - } - - if ('' === $haystack) { - return false; - } - - $needleLength = \strlen($needle); - - return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength); - } -} diff --git a/src/Php80/PhpToken.php b/src/Php80/PhpToken.php deleted file mode 100644 index fe6e69105..000000000 --- a/src/Php80/PhpToken.php +++ /dev/null @@ -1,103 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Php80; - -/** - * @author Fedonyuk Anton - * - * @internal - */ -class PhpToken implements \Stringable -{ - /** - * @var int - */ - public $id; - - /** - * @var string - */ - public $text; - - /** - * @var int - */ - public $line; - - /** - * @var int - */ - public $pos; - - public function __construct(int $id, string $text, int $line = -1, int $position = -1) - { - $this->id = $id; - $this->text = $text; - $this->line = $line; - $this->pos = $position; - } - - public function getTokenName(): ?string - { - if ('UNKNOWN' === $name = token_name($this->id)) { - $name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text; - } - - return $name; - } - - /** - * @param int|string|array $kind - */ - public function is($kind): bool - { - foreach ((array) $kind as $value) { - if (\in_array($value, [$this->id, $this->text], true)) { - return true; - } - } - - return false; - } - - public function isIgnorable(): bool - { - return \in_array($this->id, [\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_OPEN_TAG], true); - } - - public function __toString(): string - { - return (string) $this->text; - } - - /** - * @return static[] - */ - public static function tokenize(string $code, int $flags = 0): array - { - $line = 1; - $position = 0; - $tokens = token_get_all($code, $flags); - foreach ($tokens as $index => $token) { - if (\is_string($token)) { - $id = \ord($token); - $text = $token; - } else { - [$id, $text, $line] = $token; - } - $tokens[$index] = new static($id, $text, $line, $position); - $position += \strlen($text); - } - - return $tokens; - } -} diff --git a/src/Php80/Resources/stubs/Attribute.php b/src/Php80/Resources/stubs/Attribute.php deleted file mode 100644 index 2b955423f..000000000 --- a/src/Php80/Resources/stubs/Attribute.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -#[Attribute(Attribute::TARGET_CLASS)] -final class Attribute -{ - public const TARGET_CLASS = 1; - public const TARGET_FUNCTION = 2; - public const TARGET_METHOD = 4; - public const TARGET_PROPERTY = 8; - public const TARGET_CLASS_CONSTANT = 16; - public const TARGET_PARAMETER = 32; - public const TARGET_ALL = 63; - public const IS_REPEATABLE = 64; - - /** @var int */ - public $flags; - - public function __construct(int $flags = self::TARGET_ALL) - { - $this->flags = $flags; - } -} diff --git a/src/Php80/Resources/stubs/PhpToken.php b/src/Php80/Resources/stubs/PhpToken.php deleted file mode 100644 index bd1212f6e..000000000 --- a/src/Php80/Resources/stubs/PhpToken.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID < 80000 && extension_loaded('tokenizer')) { - class PhpToken extends Symfony\Polyfill\Php80\PhpToken - { - } -} diff --git a/src/Php80/Resources/stubs/Stringable.php b/src/Php80/Resources/stubs/Stringable.php deleted file mode 100644 index 7c62d7508..000000000 --- a/src/Php80/Resources/stubs/Stringable.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID < 80000) { - interface Stringable - { - /** - * @return string - */ - public function __toString(); - } -} diff --git a/src/Php80/Resources/stubs/UnhandledMatchError.php b/src/Php80/Resources/stubs/UnhandledMatchError.php deleted file mode 100644 index 01c6c6c8a..000000000 --- a/src/Php80/Resources/stubs/UnhandledMatchError.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID < 80000) { - class UnhandledMatchError extends Error - { - } -} diff --git a/src/Php80/Resources/stubs/ValueError.php b/src/Php80/Resources/stubs/ValueError.php deleted file mode 100644 index 783dbc28c..000000000 --- a/src/Php80/Resources/stubs/ValueError.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID < 80000) { - class ValueError extends Error - { - } -} diff --git a/src/Php80/bootstrap.php b/src/Php80/bootstrap.php deleted file mode 100644 index e5f7dbc1a..000000000 --- a/src/Php80/bootstrap.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Php80 as p; - -if (\PHP_VERSION_ID >= 80000) { - return; -} - -if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) { - define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN); -} - -if (!function_exists('fdiv')) { - function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); } -} -if (!function_exists('preg_last_error_msg')) { - function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); } -} -if (!function_exists('str_contains')) { - function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); } -} -if (!function_exists('str_starts_with')) { - function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); } -} -if (!function_exists('str_ends_with')) { - function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); } -} -if (!function_exists('get_debug_type')) { - function get_debug_type($value): string { return p\Php80::get_debug_type($value); } -} -if (!function_exists('get_resource_id')) { - function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); } -} diff --git a/src/Php80/composer.json b/src/Php80/composer.json index a503b039a..71bbd7387 100644 --- a/src/Php80/composer.json +++ b/src/Php80/composer.json @@ -1,6 +1,6 @@ { "name": "symfony/polyfill-php80", - "type": "library", + "type": "metapackage", "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "keywords": ["polyfill", "shim", "compatibility", "portable"], "homepage": "https://symfony.com", @@ -20,12 +20,7 @@ } ], "require": { - "php": ">=7.2" - }, - "autoload": { - "psr-4": { "Symfony\\Polyfill\\Php80\\": "" }, - "files": [ "bootstrap.php" ], - "classmap": [ "Resources/stubs" ] + "php": ">=8.0" }, "minimum-stability": "dev", "extra": { diff --git a/src/Php81/Php81.php b/src/Php81/Php81.php deleted file mode 100644 index f0507b765..000000000 --- a/src/Php81/Php81.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Php81; - -/** - * @author Nicolas Grekas - * - * @internal - */ -final class Php81 -{ - public static function array_is_list(array $array): bool - { - if ([] === $array || $array === array_values($array)) { - return true; - } - - $nextKey = -1; - - foreach ($array as $k => $v) { - if ($k !== ++$nextKey) { - return false; - } - } - - return true; - } -} diff --git a/src/Php81/Resources/stubs/CURLStringFile.php b/src/Php81/Resources/stubs/CURLStringFile.php deleted file mode 100644 index 5ff93fcaf..000000000 --- a/src/Php81/Resources/stubs/CURLStringFile.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID >= 70400 && extension_loaded('curl')) { - /** - * @property string $data - */ - class CURLStringFile extends CURLFile - { - private $data; - - public function __construct(string $data, string $postname, string $mime = 'application/octet-stream') - { - $this->data = $data; - parent::__construct('data://application/octet-stream;base64,'.base64_encode($data), $mime, $postname); - } - - public function __set(string $name, $value): void - { - if ('data' !== $name) { - $this->$name = $value; - - return; - } - - if (is_object($value) ? !method_exists($value, '__toString') : !is_scalar($value)) { - throw new TypeError('Cannot assign '.gettype($value).' to property CURLStringFile::$data of type string'); - } - - $this->name = 'data://application/octet-stream;base64,'.base64_encode($value); - } - - public function __isset(string $name): bool - { - return isset($this->$name); - } - - public function &__get(string $name) - { - return $this->$name; - } - } -} diff --git a/src/Php81/Resources/stubs/ReturnTypeWillChange.php b/src/Php81/Resources/stubs/ReturnTypeWillChange.php deleted file mode 100644 index cb7720a8d..000000000 --- a/src/Php81/Resources/stubs/ReturnTypeWillChange.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID < 80100) { - #[Attribute(Attribute::TARGET_METHOD)] - final class ReturnTypeWillChange - { - public function __construct() - { - } - } -} diff --git a/src/Php81/bootstrap.php b/src/Php81/bootstrap.php deleted file mode 100644 index 9f872e02f..000000000 --- a/src/Php81/bootstrap.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Php81 as p; - -if (\PHP_VERSION_ID >= 80100) { - return; -} - -if (defined('MYSQLI_REFRESH_SLAVE') && !defined('MYSQLI_REFRESH_REPLICA')) { - define('MYSQLI_REFRESH_REPLICA', 64); -} - -if (!function_exists('array_is_list')) { - function array_is_list(array $array): bool { return p\Php81::array_is_list($array); } -} - -if (!function_exists('enum_exists')) { - function enum_exists(string $enum, bool $autoload = true): bool { return $autoload && class_exists($enum) && false; } -} diff --git a/src/Php81/composer.json b/src/Php81/composer.json index 28b6408ea..2b674ab82 100644 --- a/src/Php81/composer.json +++ b/src/Php81/composer.json @@ -1,6 +1,6 @@ { "name": "symfony/polyfill-php81", - "type": "library", + "type": "metapackage", "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", "keywords": ["polyfill", "shim", "compatibility", "portable"], "homepage": "https://symfony.com", @@ -16,12 +16,7 @@ } ], "require": { - "php": ">=7.2" - }, - "autoload": { - "psr-4": { "Symfony\\Polyfill\\Php81\\": "" }, - "files": [ "bootstrap.php" ], - "classmap": [ "Resources/stubs" ] + "php": ">=8.1" }, "minimum-stability": "dev", "extra": { diff --git a/src/Php82/composer.json b/src/Php82/composer.json index 2031ae8d0..00c594993 100644 --- a/src/Php82/composer.json +++ b/src/Php82/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Php82\\": "" }, diff --git a/src/Php83/bootstrap.php b/src/Php83/bootstrap.php index a92799cb3..e5a166526 100644 --- a/src/Php83/bootstrap.php +++ b/src/Php83/bootstrap.php @@ -37,14 +37,10 @@ function str_increment(string $string): string { return p\Php83::str_increment($ function str_decrement(string $string): string { return p\Php83::str_decrement($string); } } -if (\PHP_VERSION_ID >= 80100) { - return require __DIR__.'/bootstrap81.php'; -} - if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) { - function ldap_exop_sync($ldap, string $request_oid, ?string $request_data = null, ?array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } + function ldap_exop_sync(\LDAP\Connection $ldap, string $request_oid, ?string $request_data = null, ?array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } } if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) { - function ldap_connect_wallet(?string $uri, string $wallet, string $password, int $auth_mode = \GSLC_SSL_NO_AUTH) { return ldap_connect($uri, $wallet, $password, $auth_mode); } + function ldap_connect_wallet(?string $uri, string $wallet, #[\SensitiveParameter] string $password, int $auth_mode = \GSLC_SSL_NO_AUTH): \LDAP\Connection|false { return ldap_connect($uri, $wallet, $password, $auth_mode); } } diff --git a/src/Php83/bootstrap81.php b/src/Php83/bootstrap81.php deleted file mode 100644 index 68395b439..000000000 --- a/src/Php83/bootstrap81.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -if (\PHP_VERSION_ID >= 80300) { - return; -} - -if (!function_exists('ldap_exop_sync') && function_exists('ldap_exop')) { - function ldap_exop_sync(\LDAP\Connection $ldap, string $request_oid, ?string $request_data = null, ?array $controls = null, &$response_data = null, &$response_oid = null): bool { return ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid); } -} - -if (!function_exists('ldap_connect_wallet') && function_exists('ldap_connect')) { - function ldap_connect_wallet(?string $uri, string $wallet, #[\SensitiveParameter] string $password, int $auth_mode = \GSLC_SSL_NO_AUTH): \LDAP\Connection|false { return ldap_connect($uri, $wallet, $password, $auth_mode); } -} diff --git a/src/Php83/composer.json b/src/Php83/composer.json index a8b8ba707..635af4bbd 100644 --- a/src/Php83/composer.json +++ b/src/Php83/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Php83\\": "" }, diff --git a/src/Php84/composer.json b/src/Php84/composer.json index 8bbc28125..b77a2743c 100644 --- a/src/Php84/composer.json +++ b/src/Php84/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Php84\\": "" }, diff --git a/src/Util/TestListener.php b/src/Util/TestListener.php index 15071fdb2..8f907967f 100644 --- a/src/Util/TestListener.php +++ b/src/Util/TestListener.php @@ -11,14 +11,81 @@ namespace Symfony\Polyfill\Util; -if (version_compare(\PHPUnit\Runner\Version::id(), '9.1.0', '<')) { - class_alias('Symfony\Polyfill\Util\TestListenerForV7', 'Symfony\Polyfill\Util\TestListener'); -} else { - class_alias('Symfony\Polyfill\Util\TestListenerForV9', 'Symfony\Polyfill\Util\TestListener'); -} +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Test; +use PHPUnit\Framework\TestListener as TestListenerInterface; +use PHPUnit\Framework\TestSuite; +use PHPUnit\Framework\Warning; +use PHPUnit\Framework\WarningTestCase; + +class TestListener extends TestSuite implements TestListenerInterface +{ + private $trait; + + public function __construct(?TestSuite $suite = null) + { + if ($suite) { + $this->setName($suite->getName().' with polyfills enabled'); + $this->addTest($suite); + } + $this->trait = new TestListenerTrait(); + } + + public function startTestSuite(TestSuite $suite): void + { + if (null === TestListenerTrait::$enabledPolyfills) { + TestListenerTrait::$enabledPolyfills = false; + $this->trait->startTestSuite($suite); + } + if ($suite instanceof TestListener) { + TestListenerTrait::$enabledPolyfills = $suite->getName(); + } + } + + public function addError(Test $test, \Throwable $t, float $time): void + { + $this->trait->addError($test, $t, $time); + } + + public function addWarning($test, ?Warning $e = null, ?float $time = null): void + { + if (\is_string($test)) { + parent::addWarning($test); + } + } + + public function addFailure(Test $test, AssertionFailedError $e, float $time): void + { + $this->trait->addError($test, $e, $time); + } + + public function addIncompleteTest(Test $test, \Throwable $t, float $time): void + { + } + + public function addRiskyTest(Test $test, \Throwable $t, float $time): void + { + } + + public function addSkippedTest(Test $test, \Throwable $t, float $time): void + { + } + + public function endTestSuite(TestSuite $suite): void + { + TestListenerTrait::$enabledPolyfills = false; + } + + public function startTest(Test $test): void + { + } + + public function endTest(Test $test, float $time): void + { + } -if (false) { - class TestListener + public static function warning($message): WarningTestCase { + return new WarningTestCase($message); } } diff --git a/src/Util/TestListenerForV7.php b/src/Util/TestListenerForV7.php deleted file mode 100644 index a2a29f32b..000000000 --- a/src/Util/TestListenerForV7.php +++ /dev/null @@ -1,91 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Util; - -use PHPUnit\Framework\AssertionFailedError; -use PHPUnit\Framework\Test; -use PHPUnit\Framework\TestListener as TestListenerInterface; -use PHPUnit\Framework\TestSuite; -use PHPUnit\Framework\Warning; -use PHPUnit\Framework\WarningTestCase; - -/** - * @author Ion Bazan - */ -class TestListenerForV7 extends TestSuite implements TestListenerInterface -{ - private $trait; - - public function __construct(?TestSuite $suite = null) - { - if ($suite) { - $this->setName($suite->getName().' with polyfills enabled'); - $this->addTest($suite); - } - $this->trait = new TestListenerTrait(); - } - - public function startTestSuite(TestSuite $suite): void - { - if (null === TestListenerTrait::$enabledPolyfills) { - TestListenerTrait::$enabledPolyfills = false; - $this->trait->startTestSuite($suite); - } - if ($suite instanceof TestListener) { - TestListenerTrait::$enabledPolyfills = $suite->getName(); - } - } - - public function addError(Test $test, \Throwable $t, float $time): void - { - $this->trait->addError($test, $t, $time); - } - - public function addWarning(Test $test, Warning $e, float $time): void - { - } - - public function addFailure(Test $test, AssertionFailedError $e, float $time): void - { - $this->trait->addError($test, $e, $time); - } - - public function addIncompleteTest(Test $test, \Throwable $t, float $time): void - { - } - - public function addRiskyTest(Test $test, \Throwable $t, float $time): void - { - } - - public function addSkippedTest(Test $test, \Throwable $t, float $time): void - { - } - - public function endTestSuite(TestSuite $suite): void - { - TestListenerTrait::$enabledPolyfills = false; - } - - public function startTest(Test $test): void - { - } - - public function endTest(Test $test, float $time): void - { - } - - public static function warning($message): WarningTestCase - { - return new WarningTestCase($message); - } -} diff --git a/src/Util/TestListenerForV9.php b/src/Util/TestListenerForV9.php deleted file mode 100644 index f636446fe..000000000 --- a/src/Util/TestListenerForV9.php +++ /dev/null @@ -1,91 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Util; - -use PHPUnit\Framework\AssertionFailedError; -use PHPUnit\Framework\Test; -use PHPUnit\Framework\TestListener as TestListenerInterface; -use PHPUnit\Framework\TestSuite; -use PHPUnit\Framework\Warning; -use PHPUnit\Framework\WarningTestCase; - -class TestListenerForV9 extends TestSuite implements TestListenerInterface -{ - private $trait; - - public function __construct(?TestSuite $suite = null) - { - if ($suite) { - $this->setName($suite->getName().' with polyfills enabled'); - $this->addTest($suite); - } - $this->trait = new TestListenerTrait(); - } - - public function startTestSuite(TestSuite $suite): void - { - if (null === TestListenerTrait::$enabledPolyfills) { - TestListenerTrait::$enabledPolyfills = false; - $this->trait->startTestSuite($suite); - } - if ($suite instanceof TestListener) { - TestListenerTrait::$enabledPolyfills = $suite->getName(); - } - } - - public function addError(Test $test, \Throwable $t, float $time): void - { - $this->trait->addError($test, $t, $time); - } - - public function addWarning($test, ?Warning $e = null, ?float $time = null): void - { - if (\is_string($test)) { - parent::addWarning($test); - } - } - - public function addFailure(Test $test, AssertionFailedError $e, float $time): void - { - $this->trait->addError($test, $e, $time); - } - - public function addIncompleteTest(Test $test, \Throwable $t, float $time): void - { - } - - public function addRiskyTest(Test $test, \Throwable $t, float $time): void - { - } - - public function addSkippedTest(Test $test, \Throwable $t, float $time): void - { - } - - public function endTestSuite(TestSuite $suite): void - { - TestListenerTrait::$enabledPolyfills = false; - } - - public function startTest(Test $test): void - { - } - - public function endTest(Test $test, float $time): void - { - } - - public static function warning($message): WarningTestCase - { - return new WarningTestCase($message); - } -} diff --git a/src/Util/TestListenerTrait.php b/src/Util/TestListenerTrait.php index 9527b52bb..169316550 100644 --- a/src/Util/TestListenerTrait.php +++ b/src/Util/TestListenerTrait.php @@ -12,6 +12,7 @@ namespace Symfony\Polyfill\Util; use PHPUnit\Framework\SkippedTestError; +use PHPUnit\Framework\TestSuite; use PHPUnit\Util\Test; use Symfony\Component\VarDumper\Caster\ReflectionCaster; use Symfony\Component\VarDumper\Cloner\Stub; @@ -23,13 +24,19 @@ class TestListenerTrait { public static $enabledPolyfills; - public function startTestSuite($mainSuite) + public function startTestSuite(TestSuite $mainSuite) { $warnings = []; foreach ($mainSuite->tests() as $suite) { $testClass = $suite->getName(); - if (!$tests = $suite->tests()) { + if (!class_exists($testClass)) { + $this->startTestSuite($suite); + + continue; + } + + if (!$suite->tests()) { continue; } if (\in_array('class-polyfill', Test::getGroups($testClass), true)) { @@ -48,8 +55,7 @@ public function startTestSuite($mainSuite) continue; } $testedClass = new \ReflectionClass($m[1].$m[2]); - $bootstrap = \dirname($testedClass->getFileName()).'/bootstrap'; - $bootstrap = new \SplFileObject($bootstrap.(\PHP_VERSION_ID >= 80000 && file_exists($bootstrap.'80.php') ? '80' : '').'.php'); + $bootstrap = new \SplFileObject(\dirname($testedClass->getFileName()).'/bootstrap.php'); $newWarnings = 0; $defLine = null; @@ -114,7 +120,7 @@ function {$f['name']}{$f['signature']} EOPHP ); - if (\PHP_VERSION_ID >= 80000 && $r && false === strpos($bootstrap->getPath(), 'Php7') && false === strpos($bootstrap->getPath(), 'Php80')) { + if ($r) { $originalSignature = ReflectionCaster::getSignature(ReflectionCaster::castFunctionAbstract($r, [], new Stub(), true)); $polyfillSignature = ReflectionCaster::castFunctionAbstract(new \ReflectionFunction($testNamespace.'\\'.$f['name']), [], new Stub(), true); $polyfillSignature = ReflectionCaster::getSignature($polyfillSignature); diff --git a/src/Util/composer.json b/src/Util/composer.json index 773bb2d53..997b9c443 100644 --- a/src/Util/composer.json +++ b/src/Util/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "autoload": { "psr-4": { "Symfony\\Polyfill\\Util\\": "" } diff --git a/src/Uuid/Uuid.php b/src/Uuid/Uuid.php index 584095b14..4cf172b27 100644 --- a/src/Uuid/Uuid.php +++ b/src/Uuid/Uuid.php @@ -77,10 +77,6 @@ public static function uuid_generate_md5($uuid_ns, $name) } if (!self::isValid($uuid_ns)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_generate_md5(): Argument #1 ($uuid_ns) UUID expected'); } @@ -118,10 +114,6 @@ public static function uuid_generate_sha1($uuid_ns, $name) } if (!self::isValid($uuid_ns)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_generate_sha1(): Argument #1 ($uuid_ns) UUID expected'); } @@ -172,18 +164,10 @@ public static function uuid_compare($uuid1, $uuid2) } if (!self::isValid($uuid1)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_compare(): Argument #1 ($uuid1) UUID expected'); } if (!self::isValid($uuid2)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_compare(): Argument #2 ($uuid2) UUID expected'); } @@ -197,7 +181,7 @@ public static function uuid_is_null($uuid) return null; } - if (80000 <= \PHP_VERSION_ID && !self::isValid($uuid)) { + if (!self::isValid($uuid)) { throw new \ValueError('uuid_is_null(): Argument #1 ($uuid) UUID expected'); } @@ -217,10 +201,6 @@ public static function uuid_type($uuid) } if (null === $parsed = self::parse($uuid)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_type(): Argument #1 ($uuid) UUID expected'); } @@ -240,10 +220,6 @@ public static function uuid_variant($uuid) } if (null === $parsed = self::parse($uuid)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_variant(): Argument #1 ($uuid) UUID expected'); } @@ -271,10 +247,6 @@ public static function uuid_time($uuid) $parsed = self::parse($uuid); if (self::UUID_TYPE_TIME !== ($parsed['version'] ?? null)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_time(): Argument #1 ($uuid) UUID DCE TIME expected'); } @@ -300,10 +272,6 @@ public static function uuid_mac($uuid) $parsed = self::parse($uuid); if (self::UUID_TYPE_TIME !== ($parsed['version'] ?? null)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_mac(): Argument #1 ($uuid) UUID DCE TIME expected'); } @@ -319,10 +287,6 @@ public static function uuid_parse($uuid) } if (!self::isValid($uuid)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_parse(): Argument #1 ($uuid) UUID expected'); } @@ -338,10 +302,6 @@ public static function uuid_unparse($bytes) } if (16 !== \strlen($bytes)) { - if (80000 > \PHP_VERSION_ID) { - return false; - } - throw new \ValueError('uuid_unparse(): Argument #1 ($uuid) UUID expected'); } diff --git a/src/Uuid/bootstrap.php b/src/Uuid/bootstrap.php index 6d8545b3a..411e75e27 100644 --- a/src/Uuid/bootstrap.php +++ b/src/Uuid/bootstrap.php @@ -15,10 +15,6 @@ return; } -if (\PHP_VERSION_ID >= 80000) { - return require __DIR__.'/bootstrap80.php'; -} - if (!defined('UUID_VARIANT_NCS')) { define('UUID_VARIANT_NCS', 0); } @@ -60,38 +56,38 @@ } if (!function_exists('uuid_create')) { - function uuid_create($uuid_type = \UUID_TYPE_DEFAULT) { return p\Uuid::uuid_create($uuid_type); } + function uuid_create(?int $uuid_type = \UUID_TYPE_DEFAULT): string { return p\Uuid::uuid_create((int) $uuid_type); } } if (!function_exists('uuid_generate_md5')) { - function uuid_generate_md5($uuid_ns, $name) { return p\Uuid::uuid_generate_md5($uuid_ns, $name); } + function uuid_generate_md5(?string $uuid_ns, ?string $name): string { return p\Uuid::uuid_generate_md5((string) $uuid_ns, (string) $name); } } if (!function_exists('uuid_generate_sha1')) { - function uuid_generate_sha1($uuid_ns, $name) { return p\Uuid::uuid_generate_sha1($uuid_ns, $name); } + function uuid_generate_sha1(?string $uuid_ns, ?string $name): string { return p\Uuid::uuid_generate_sha1((string) $uuid_ns, (string) $name); } } if (!function_exists('uuid_is_valid')) { - function uuid_is_valid($uuid) { return p\Uuid::uuid_is_valid($uuid); } + function uuid_is_valid(?string $uuid): bool { return p\Uuid::uuid_is_valid((string) $uuid); } } if (!function_exists('uuid_compare')) { - function uuid_compare($uuid1, $uuid2) { return p\Uuid::uuid_compare($uuid1, $uuid2); } + function uuid_compare(?string $uuid1, ?string $uuid2): int { return p\Uuid::uuid_compare((string) $uuid1, (string) $uuid2); } } if (!function_exists('uuid_is_null')) { - function uuid_is_null($uuid) { return p\Uuid::uuid_is_null($uuid); } + function uuid_is_null(?string $uuid): bool { return p\Uuid::uuid_is_null((string) $uuid); } } if (!function_exists('uuid_type')) { - function uuid_type($uuid) { return p\Uuid::uuid_type($uuid); } + function uuid_type(?string $uuid): int { return p\Uuid::uuid_type((string) $uuid); } } if (!function_exists('uuid_variant')) { - function uuid_variant($uuid) { return p\Uuid::uuid_variant($uuid); } + function uuid_variant(?string $uuid): int { return p\Uuid::uuid_variant((string) $uuid); } } if (!function_exists('uuid_time')) { - function uuid_time($uuid) { return p\Uuid::uuid_time($uuid); } + function uuid_time(?string $uuid): int { return p\Uuid::uuid_time((string) $uuid); } } if (!function_exists('uuid_mac')) { - function uuid_mac($uuid) { return p\Uuid::uuid_mac($uuid); } + function uuid_mac(?string $uuid): string { return p\Uuid::uuid_mac((string) $uuid); } } if (!function_exists('uuid_parse')) { - function uuid_parse($uuid) { return p\Uuid::uuid_parse($uuid); } + function uuid_parse(?string $uuid): string { return p\Uuid::uuid_parse((string) $uuid); } } if (!function_exists('uuid_unparse')) { - function uuid_unparse($uuid) { return p\Uuid::uuid_unparse($uuid); } + function uuid_unparse(?string $uuid): string { return p\Uuid::uuid_unparse((string) $uuid); } } diff --git a/src/Uuid/bootstrap80.php b/src/Uuid/bootstrap80.php deleted file mode 100644 index d6c592fe8..000000000 --- a/src/Uuid/bootstrap80.php +++ /dev/null @@ -1,89 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Polyfill\Uuid as p; - -if (!defined('UUID_VARIANT_NCS')) { - define('UUID_VARIANT_NCS', 0); -} -if (!defined('UUID_VARIANT_DCE')) { - define('UUID_VARIANT_DCE', 1); -} -if (!defined('UUID_VARIANT_MICROSOFT')) { - define('UUID_VARIANT_MICROSOFT', 2); -} -if (!defined('UUID_VARIANT_OTHER')) { - define('UUID_VARIANT_OTHER', 3); -} -if (!defined('UUID_TYPE_DEFAULT')) { - define('UUID_TYPE_DEFAULT', 0); -} -if (!defined('UUID_TYPE_TIME')) { - define('UUID_TYPE_TIME', 1); -} -if (!defined('UUID_TYPE_MD5')) { - define('UUID_TYPE_MD5', 3); -} -if (!defined('UUID_TYPE_DCE')) { - define('UUID_TYPE_DCE', 4); // Deprecated alias -} -if (!defined('UUID_TYPE_NAME')) { - define('UUID_TYPE_NAME', 1); // Deprecated alias -} -if (!defined('UUID_TYPE_RANDOM')) { - define('UUID_TYPE_RANDOM', 4); -} -if (!defined('UUID_TYPE_SHA1')) { - define('UUID_TYPE_SHA1', 5); -} -if (!defined('UUID_TYPE_NULL')) { - define('UUID_TYPE_NULL', -1); -} -if (!defined('UUID_TYPE_INVALID')) { - define('UUID_TYPE_INVALID', -42); -} - -if (!function_exists('uuid_create')) { - function uuid_create(?int $uuid_type = \UUID_TYPE_DEFAULT): string { return p\Uuid::uuid_create((int) $uuid_type); } -} -if (!function_exists('uuid_generate_md5')) { - function uuid_generate_md5(?string $uuid_ns, ?string $name): string { return p\Uuid::uuid_generate_md5((string) $uuid_ns, (string) $name); } -} -if (!function_exists('uuid_generate_sha1')) { - function uuid_generate_sha1(?string $uuid_ns, ?string $name): string { return p\Uuid::uuid_generate_sha1((string) $uuid_ns, (string) $name); } -} -if (!function_exists('uuid_is_valid')) { - function uuid_is_valid(?string $uuid): bool { return p\Uuid::uuid_is_valid((string) $uuid); } -} -if (!function_exists('uuid_compare')) { - function uuid_compare(?string $uuid1, ?string $uuid2): int { return p\Uuid::uuid_compare((string) $uuid1, (string) $uuid2); } -} -if (!function_exists('uuid_is_null')) { - function uuid_is_null(?string $uuid): bool { return p\Uuid::uuid_is_null((string) $uuid); } -} -if (!function_exists('uuid_type')) { - function uuid_type(?string $uuid): int { return p\Uuid::uuid_type((string) $uuid); } -} -if (!function_exists('uuid_variant')) { - function uuid_variant(?string $uuid): int { return p\Uuid::uuid_variant((string) $uuid); } -} -if (!function_exists('uuid_time')) { - function uuid_time(?string $uuid): int { return p\Uuid::uuid_time((string) $uuid); } -} -if (!function_exists('uuid_mac')) { - function uuid_mac(?string $uuid): string { return p\Uuid::uuid_mac((string) $uuid); } -} -if (!function_exists('uuid_parse')) { - function uuid_parse(?string $uuid): string { return p\Uuid::uuid_parse((string) $uuid); } -} -if (!function_exists('uuid_unparse')) { - function uuid_unparse(?string $uuid): string { return p\Uuid::uuid_unparse((string) $uuid); } -} diff --git a/src/Uuid/composer.json b/src/Uuid/composer.json index f3c5045d5..993f56552 100644 --- a/src/Uuid/composer.json +++ b/src/Uuid/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=7.2" + "php": ">=8.1" }, "provide": { "ext-uuid": "*" diff --git a/src/bootstrap.php b/src/bootstrap.php index 56a216d58..121976a11 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -9,22 +9,6 @@ * file that was distributed with this source code. */ -if (\PHP_VERSION_ID < 70300) { - require __DIR__.'/Php73/bootstrap.php'; -} - -if (\PHP_VERSION_ID < 70400) { - require __DIR__.'/Php74/bootstrap.php'; -} - -if (\PHP_VERSION_ID < 80000) { - require __DIR__.'/Php80/bootstrap.php'; -} - -if (\PHP_VERSION_ID < 80100) { - require __DIR__.'/Php81/bootstrap.php'; -} - if (\PHP_VERSION_ID < 80200) { require __DIR__.'/Php82/bootstrap.php'; } diff --git a/tests/Iconv/IconvTest.php b/tests/Iconv/IconvTest.php index e72b71a1c..bebf5a966 100644 --- a/tests/Iconv/IconvTest.php +++ b/tests/Iconv/IconvTest.php @@ -67,21 +67,6 @@ public function testIconvSubstr() /** * @covers \Symfony\Polyfill\Iconv\Iconv::iconv_substr - * - * @requires PHP < 8 - */ - public function testIconvSubstrReturnsFalsePrePHP8() - { - $c = 'déjà'; - $this->assertFalse(iconv_substr($c, 42, 1, 'UTF-8')); - $this->assertFalse(iconv_substr($c, -42, 1)); - $this->assertFalse(iconv_substr($c, 42, 26)); - } - - /** - * @covers \Symfony\Polyfill\Iconv\Iconv::iconv_substr - * - * @requires PHP 8 */ public function testIconvSubstrReturnsEmptyPostPHP8() { diff --git a/tests/Intl/Grapheme/GraphemeTest.php b/tests/Intl/Grapheme/GraphemeTest.php index 7bd77241f..b19726daa 100644 --- a/tests/Intl/Grapheme/GraphemeTest.php +++ b/tests/Intl/Grapheme/GraphemeTest.php @@ -27,14 +27,7 @@ class GraphemeTest extends TestCase public function testGraphemeExtractArrayError() { grapheme_extract('', 0); - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(@grapheme_extract([], 0)); - - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 1 to be string, array given'); - } else { - $this->expectException(\TypeError::class); - } + $this->expectException(\TypeError::class); grapheme_extract([], 0); } @@ -66,12 +59,10 @@ public function testGraphemeExtract() */ public function testGraphemeExtractWithInvalidType() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS'); - $this->assertFalse(grapheme_extract('abc', 1, -1)); + grapheme_extract('abc', 1, -1); } /** @@ -104,16 +95,9 @@ public function testGraphemeSubstr() $this->assertSame('jà', grapheme_substr($c, -2, null)); - if (\PHP_VERSION_ID >= 80000) { - $this->assertSame('jà', grapheme_substr($c, -2, 3)); - $this->assertSame('', grapheme_substr($c, -1, 0)); - $this->assertSame('', grapheme_substr($c, 1, -4)); - } else { - // See http://bugs.php.net/62759 and 55562 - $this->assertSame('jà', grapheme_substr($c, -2, 3)); - $this->assertSame('', grapheme_substr($c, -1, 0)); - $this->assertFalse(grapheme_substr($c, 1, -4)); - } + $this->assertSame('jà', grapheme_substr($c, -2, 3)); + $this->assertSame('', grapheme_substr($c, -1, 0)); + $this->assertSame('', grapheme_substr($c, 1, -4)); $this->assertSame('jà', grapheme_substr($c, 2)); $this->assertSame('jà', grapheme_substr($c, -2)); @@ -125,22 +109,6 @@ public function testGraphemeSubstr() /** * @covers \Symfony\Polyfill\Intl\Grapheme\Grapheme::grapheme_substr - * - * @requires PHP < 8 - */ - public function testGraphemeSubstrReturnsFalsePrePHP8() - { - $c = 'déjà'; - $this->assertFalse(grapheme_substr($c, 5, 1)); - $this->assertFalse(grapheme_substr($c, -5, 1)); - $this->assertFalse(grapheme_substr($c, -42, 1)); - $this->assertFalse(grapheme_substr($c, 42, 5)); - } - - /** - * @covers \Symfony\Polyfill\Intl\Grapheme\Grapheme::grapheme_substr - * - * @requires PHP 8 */ public function testGraphemeSubstrReturnsEmptyPostPHP8() { @@ -160,21 +128,13 @@ public function testGraphemeSubstrReturnsEmptyPostPHP8() */ public function testGraphemeStrpos() { - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(grapheme_strpos('abc', '')); - } else { - $this->assertSame(0, grapheme_strpos('abc', '')); - } + $this->assertSame(0, grapheme_strpos('abc', '')); $this->assertFalse(grapheme_strpos('abc', 'd')); $this->assertFalse(grapheme_strpos('abc', 'a', 3)); $this->assertFalse(grapheme_strpos('abc', 'a', -1)); $this->assertSame(1, grapheme_strpos('한국어', '국')); $this->assertSame(3, grapheme_stripos('DÉJÀ', 'à')); - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(grapheme_strrpos('한국어', '')); - } else { - $this->assertSame(3, grapheme_strrpos('한국어', '')); - } + $this->assertSame(3, grapheme_strrpos('한국어', '')); $this->assertSame(1, grapheme_strrpos('한국어', '국')); $this->assertSame(3, grapheme_strripos('DÉJÀ', 'à')); } diff --git a/tests/Intl/Icu/AbstractNumberFormatterTest.php b/tests/Intl/Icu/AbstractNumberFormatterTest.php index e5f470794..98bbe9e86 100644 --- a/tests/Intl/Icu/AbstractNumberFormatterTest.php +++ b/tests/Intl/Icu/AbstractNumberFormatterTest.php @@ -342,13 +342,7 @@ public static function formatTypeDoubleWithCurrencyStyleProvider() */ public function testFormatTypeCurrency($formatter, $value) { - if (\PHP_VERSION_ID >= 80000) { - $this->expectException(\ValueError::class); - } elseif (method_exists($this, 'expectWarning')) { - $this->expectWarning(); - } else { - $this->expectException(Warning::class); - } + $this->expectException(\ValueError::class); $formatter->format($value, NumberFormatter::TYPE_CURRENCY); } @@ -358,11 +352,9 @@ public function testFormatTypeCurrency($formatter, $value) */ public function testFormatTypeCurrencyReturn($formatter, $value) { - if (\PHP_VERSION_ID >= 80000) { - $this->expectException(\ValueError::class); - } + $this->expectException(\ValueError::class); - $this->assertFalse(@$formatter->format($value, NumberFormatter::TYPE_CURRENCY)); + @$formatter->format($value, NumberFormatter::TYPE_CURRENCY); } public static function formatTypeCurrencyProvider() @@ -729,13 +721,7 @@ public static function parseProvider() public function testParseTypeDefault() { - if (\PHP_VERSION_ID >= 80000) { - $this->expectException(\ValueError::class); - } elseif (method_exists($this, 'expectWarning')) { - $this->expectWarning(); - } else { - $this->expectException(Warning::class); - } + $this->expectException(\ValueError::class); $formatter = static::getNumberFormatter('en', NumberFormatter::DECIMAL); $formatter->parse('1', NumberFormatter::TYPE_DEFAULT); @@ -863,13 +849,7 @@ public static function parseTypeDoubleProvider() public function testParseTypeCurrency() { - if (\PHP_VERSION_ID >= 80000) { - $this->expectException(\ValueError::class); - } elseif (method_exists($this, 'expectWarning')) { - $this->expectWarning(); - } else { - $this->expectException(Warning::class); - } + $this->expectException(\ValueError::class); $formatter = static::getNumberFormatter('en', NumberFormatter::DECIMAL); $formatter->parse('1', NumberFormatter::TYPE_CURRENCY); diff --git a/tests/Intl/Icu/Verification/IntlDateFormatterTest.php b/tests/Intl/Icu/Verification/IntlDateFormatterTest.php index da88e3241..707f920c7 100644 --- a/tests/Intl/Icu/Verification/IntlDateFormatterTest.php +++ b/tests/Intl/Icu/Verification/IntlDateFormatterTest.php @@ -26,18 +26,6 @@ */ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest { - /** - * @dataProvider formatProvider - */ - public function testFormat($pattern, $timestamp, $expected) - { - if (\PHP_VERSION_ID < 70105 && $timestamp instanceof \DateTimeImmutable) { - $this->markTestSkipped('PHP >= 7.1.5 required for DateTimeImmutable.'); - } - - parent::testFormat($pattern, $timestamp, $expected); - } - /** * @dataProvider formatTimezoneProvider */ @@ -72,8 +60,6 @@ public function testDateAndTimeType($timestamp, $datetype, $timetype, $expected) } /** - * @requires PHP 8 - * * @dataProvider relativeDateTypeProvider */ public function testRelativeDateType($timestamp, $datetype, $timetype, $expected) @@ -85,9 +71,6 @@ public function testRelativeDateType($timestamp, $datetype, $timetype, $expected parent::testRelativeDateType($timestamp, $datetype, $timetype, $expected); } - /** - * @requires PHP 8 - */ public function testFormatIgnoresPatternForRelativeDateType() { if (version_compare(\INTL_ICU_VERSION, '59.1', '<')) { diff --git a/tests/Intl/Idn/IdnTest.php b/tests/Intl/Idn/IdnTest.php index bf5b60017..8eabb54f7 100644 --- a/tests/Intl/Idn/IdnTest.php +++ b/tests/Intl/Idn/IdnTest.php @@ -205,19 +205,6 @@ public function testToAsciiTransitional($source, $toUnicode, $toUnicodeStatus, $ } } - /** - * @requires PHP < 8 - * - * @group legacy - * - * @dataProvider domainNamesProvider - */ - public function testEncode2003($decoded, $encoded) - { - $result = @idn_to_ascii($decoded, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_2003); - $this->assertSame($encoded, $result); - } - /** * @dataProvider invalidUtf8DomainNamesProvider */ @@ -227,19 +214,6 @@ public function testEncodeInvalid($decoded) $this->assertFalse($result); } - /** - * @requires PHP < 8 - * - * @group legacy - * - * @dataProvider domainNamesProvider - */ - public function testDecode2003($decoded, $encoded) - { - $result = @idn_to_utf8($encoded, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_2003); - $this->assertSame($decoded, $result); - } - /** * @dataProvider domainNamesProvider */ @@ -286,19 +260,6 @@ public function testUppercaseUTS46($decoded, $ascii, $encoded) $this->assertSame($expected, $info); } - /** - * @requires PHP < 8 - * - * @group legacy - * - * @dataProvider domainNamesProvider - */ - public function testEncodePhp53($decoded, $encoded) - { - $result = @Idn::idn_to_ascii($decoded, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_2003); - $this->assertSame($encoded, $result); - } - /** * IDNA 15.1.0 revision 31. * diff --git a/tests/Intl/Normalizer/NormalizerTest.php b/tests/Intl/Normalizer/NormalizerTest.php index 7cdb74551..e5088ce41 100644 --- a/tests/Intl/Normalizer/NormalizerTest.php +++ b/tests/Intl/Normalizer/NormalizerTest.php @@ -67,11 +67,6 @@ public function testIsNormalized() */ public function testNormalize() { - $c = in::normalize('déjà', pn::NFC).in::normalize('훈쇼™', pn::NFD); - if (\PHP_VERSION_ID < 70300) { - $this->assertSame($c, normalizer_normalize($c, in::NONE)); - } - $c = 'déjà 훈쇼™'; $d = in::normalize($c, pn::NFD); $kc = in::normalize($c, pn::NFKC); @@ -95,10 +90,8 @@ public function testNormalize() */ public function testNormalizeWithInvalidForm() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form'); $this->assertFalse(normalizer_normalize('foo', -1)); } diff --git a/tests/Mbstring/MbstringTest.php b/tests/Mbstring/MbstringTest.php index 2020f4566..ab1937711 100644 --- a/tests/Mbstring/MbstringTest.php +++ b/tests/Mbstring/MbstringTest.php @@ -42,10 +42,8 @@ public function testStubs() */ public function testSubstituteCharacterWithInvalidCharacter() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); $this->assertFalse(@mb_substitute_character('?')); } @@ -55,10 +53,8 @@ public function testSubstituteCharacterWithInvalidCharacter() */ public function testInternalEncodingWithInvalidEncoding() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('Argument #1 ($encoding) must be a valid encoding, "no-no" given'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('Argument #1 ($encoding) must be a valid encoding, "no-no" given'); $this->assertFalse(@mb_internal_encoding('no-no')); } @@ -99,11 +95,7 @@ public function testConvertEncodingWithArrayValue() public function testDecodeNumericEntity() { $convmap = [0x80, 0x10FFFF, 0x1, 0x1FFFFF]; - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(@mb_decode_numericentity('déjà', [], 'UTF-8')); - } else { - $this->assertSame('déjà', mb_decode_numericentity('déjà', [], 'UTF-8')); - } + $this->assertSame('déjà', mb_decode_numericentity('déjà', [], 'UTF-8')); $this->assertSame('', mb_decode_numericentity('', $convmap, 'UTF-8')); $iso = 'déjà & &225; &#E1; á &#e1; á'; @@ -133,31 +125,12 @@ public function testDecodeNumericEntity() $this->assertSame("\xFE", mb_decode_numericentity('ş', $convmap, 'ISO-8859-9')); } - /** - * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_decode_numericentity - * - * @requires PHP < 8 - */ - public function testDecodeNumericEntityWithInvalidTypes() - { - $convmap = [0x80, 0x10FFFF, 0x1, 0x1FFFFF]; - - $this->assertNull(@mb_decode_numericentity(new \stdClass(), $convmap, 'UTF-8')); - $this->assertFalse(@mb_decode_numericentity('déjà', new \stdClass(), 'UTF-8')); - $this->assertEmpty(@mb_decode_numericentity('déjà', $convmap, new \stdClass())); // PHPUnit returns null. - } - /** * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_decode_numericentity */ public function testDecodeNumericEntityWarnsOnInvalidInputType() { - if (80000 > \PHP_VERSION_ID) { - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 1 to be string'); - } else { - $this->expectException(\TypeError::class); - } + $this->expectException(\TypeError::class); mb_decode_numericentity(new \stdClass(), [0x0, 0x10FFFF, 0x0, 0x1FFFFF], 'UTF-8'); } @@ -166,12 +139,7 @@ public function testDecodeNumericEntityWarnsOnInvalidInputType() */ public function testDecodeNumericEntityWarnsOnInvalidEncodingType() { - if (80000 > \PHP_VERSION_ID) { - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 3 to be string'); - } else { - $this->expectException(\TypeError::class); - } + $this->expectException(\TypeError::class); mb_decode_numericentity('déjà', [0x0, 0x10FFFF, 0x0, 0x1FFFFF], new \stdClass()); } @@ -181,11 +149,7 @@ public function testDecodeNumericEntityWarnsOnInvalidEncodingType() public function testEncodeNumericEntity() { $convmap = [0x80, 0x10FFFF, 0x1, 0x1FFFFF]; - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(@mb_encode_numericentity('déjà', [], 'UTF-8')); - } else { - $this->assertSame('déjà', mb_encode_numericentity('déjà', [], 'UTF-8')); - } + $this->assertSame('déjà', mb_encode_numericentity('déjà', [], 'UTF-8')); $this->assertSame('', mb_encode_numericentity('', $convmap, 'UTF-8')); $iso = 'abc & á á á'; @@ -211,32 +175,12 @@ public function testEncodeNumericEntity() $this->assertSame("abc ğ\x9F\x98\x82", mb_encode_numericentity('abc 😂', $convmap, 'ISO-8859-9')); } - /** - * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_encode_numericentity - * - * @requires PHP < 8 - */ - public function testEncodeNumericEntityWithInvalidTypes() - { - $convmap = [0x80, 0x10FFFF, 0x1, 0x1FFFFF]; - - $this->assertNull(@mb_encode_numericentity(new \stdClass(), $convmap, 'UTF-8')); - $this->assertFalse(@mb_encode_numericentity('déjà', new \stdClass(), 'UTF-8')); - $this->assertNull(@mb_encode_numericentity('déjà', $convmap, new \stdClass())); - $this->assertNull(@mb_encode_numericentity('déjà', $convmap, 'UTF-8', new \stdClass())); - } - /** * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_decode_numericentity */ public function testEncodeNumericEntityWarnsOnInvalidInputType() { - if (80000 > \PHP_VERSION_ID) { - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 1 to be string'); - } else { - $this->expectException(\TypeError::class); - } + $this->expectException(\TypeError::class); mb_encode_numericentity(new \stdClass(), [0x0, 0x10FFFF, 0x0, 0x1FFFFF], 'UTF-8'); } @@ -245,12 +189,7 @@ public function testEncodeNumericEntityWarnsOnInvalidInputType() */ public function testEncodeNumericEntityWarnsOnInvalidEncodingType() { - if (80000 > \PHP_VERSION_ID) { - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 3 to be string'); - } else { - $this->expectException(\TypeError::class); - } + $this->expectException(\TypeError::class); mb_encode_numericentity('déjà', [0x0, 0x10FFFF, 0x0, 0x1FFFFF], new \stdClass()); } @@ -259,12 +198,7 @@ public function testEncodeNumericEntityWarnsOnInvalidEncodingType() */ public function testEncodeNumericEntityWarnsOnInvalidIsHexType() { - if (80000 > \PHP_VERSION_ID) { - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 4 to be bool'); - } else { - $this->expectException(\TypeError::class); - } + $this->expectException(\TypeError::class); mb_encode_numericentity('déjà', [0x0, 0x10FFFF, 0x0, 0x1FFFFF], 'UTF-8', new \stdClass()); } @@ -272,8 +206,6 @@ public function testEncodeNumericEntityWarnsOnInvalidIsHexType() * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_strtolower * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_strtoupper * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_convert_case - * - * @requires PHP 7.3 */ public function testStrCase() { @@ -293,23 +225,6 @@ public function testStrCase() public function testTitleCase() { for ($i = 1; $i < 127; ++$i) { - switch (\chr($i)) { - case '!': - case '"': - case '#': - case '%': - case '&': - case '*': - case ',': - case '/': - case ';': - case '?': - case '@': - case '\\': - if (\PHP_VERSION_ID < 70300) { - continue 2; - } - } $this->assertSame(mb_convert_case('a'.\chr($i).'b', \MB_CASE_TITLE, 'UTF-8'), p::mb_convert_case('a'.\chr($i).'b', \MB_CASE_TITLE, 'UTF-8'), 'Title case for char 0x'.dechex($i)); } } @@ -362,21 +277,13 @@ public function testSubstr() */ public function testStrpos() { - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(@mb_strpos('abc', '')); - } else { - $this->assertSame(0, mb_strpos('abc', '')); - } + $this->assertSame(0, mb_strpos('abc', '')); $this->assertFalse(@mb_strpos('abc', 'a', -1)); $this->assertFalse(mb_strpos('abc', 'd')); $this->assertFalse(mb_strpos('abc', 'a', 3)); $this->assertSame(1, mb_strpos('한국어', '국')); $this->assertSame(3, mb_stripos('DÉJÀ', 'à')); - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(mb_strrpos('한국어', '')); - } else { - $this->assertSame(3, mb_strrpos('한국어', '')); - } + $this->assertSame(3, mb_strrpos('한국어', '')); $this->assertSame(1, mb_strrpos('한국어', '국')); $this->assertSame(3, mb_strripos('DÉJÀ', 'à')); $this->assertSame(1, mb_stripos('aςσb', 'ΣΣ')); @@ -385,19 +292,6 @@ public function testStrpos() $this->assertSame(3, mb_strrpos('ababab', 'b', -3)); } - /** - * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_strpos - * - * @requires PHP < 8 - */ - public function testStrposEmptyDelimiter() - { - mb_strpos('abc', 'a'); - $this->expectWarning(); - $this->expectWarningMessage('Empty delimiter'); - mb_strpos('abc', ''); - } - /** * @covers \Symfony\Polyfill\Mbstring\Mbstring::mb_strpos */ @@ -421,10 +315,6 @@ public function testStrSplit() $this->assertSame(['alpha', 'bet'], mb_str_split('alphabet', 5)); $this->assertSame(['e', '́', '💩', '𐍈'], mb_str_split('é💩𐍈', 1, 'UTF-8')); $this->assertSame([], mb_str_split('', 1, 'UTF-8')); - - if (80000 > \PHP_VERSION_ID) { - $this->assertNull(@mb_str_split([], 0)); - } } /** @@ -432,15 +322,8 @@ public function testStrSplit() */ public function testStrSplitWithInvalidLength() { - if (80000 > \PHP_VERSION_ID) { - $this->assertFalse(@mb_str_split('победа', 0)); - - $this->expectWarning(); - $this->expectWarningMessage('The length of each segment must be greater than zero'); - } else { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('Argument #2 ($length) must be greater than 0'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('Argument #2 ($length) must be greater than 0'); mb_str_split('победа', 0); } @@ -551,12 +434,10 @@ public function testLanguage() */ public function testLanguageWithInvalidLanguage() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('Argument #1 ($language) must be a valid language, "ABC" given'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('Argument #1 ($language) must be a valid language, "ABC" given'); - $this->assertFalse(@mb_language('ABC')); + mb_language('ABC'); } /** @@ -637,10 +518,6 @@ public function testDecodeMimeheader() */ public function testMbStrPad(string $expectedResult, string $string, int $length, string $padString, int $padType, ?string $encoding = null) { - if ('UTF-32' === $encoding && \PHP_VERSION_ID < 73000) { - $this->markTestSkipped('PHP < 7.3 doesn\'t handle UTF-32 encoding properly'); - } - $this->assertSame($expectedResult, mb_convert_encoding(mb_str_pad($string, $length, $padString, $padType, $encoding), 'UTF-8', $encoding ?? mb_internal_encoding())); } @@ -761,7 +638,7 @@ public static function ucFirstDataProvider(): array ['łámał', 'Łámał'], // Full case-mapping and case-folding that changes the length of the string only supported // in PHP > 7.3. - ['ßst', \PHP_VERSION_ID < 70300 ? 'ßst' : 'Ssst'], + ['ßst', 'Ssst'], ]; } @@ -776,8 +653,8 @@ public static function lcFirstDataProvider(): array ['ABS', 'aBS'], ['Đắt quá!', 'đắt quá!'], ['აბგ', 'აბგ'], - ['Lj', \PHP_VERSION_ID < 70200 ? 'Lj' : 'lj'], - ["\u{01CB}", \PHP_VERSION_ID < 70200 ? "\u{01CB}" : "\u{01CC}"], + ['Lj', 'lj'], + ["\u{01CB}", "\u{01CC}"], ["\u{01CA}", "\u{01CC}"], ["\u{01CA}\u{01CA}", "\u{01CC}\u{01CA}"], ["\u{212A}\u{01CA}", "\u{006b}\u{01CA}"], diff --git a/tests/Php73/Php73Test.php b/tests/Php73/Php73Test.php deleted file mode 100644 index fb20aade0..000000000 --- a/tests/Php73/Php73Test.php +++ /dev/null @@ -1,169 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php73; - -use PHPUnit\Framework\TestCase; - -/** - * @author Gabriel Caruso - * @author Pierre du Plessis - */ -class Php73Test extends TestCase -{ - public function testIsCountable() - { - $this->assertTrue(is_countable([1, 2, '3'])); - $this->assertTrue(is_countable(new \ArrayIterator(['foo', 'bar', 'baz']))); - $this->assertTrue(is_countable(new \ArrayIterator())); - $this->assertTrue(is_countable(new \SimpleXMLElement(''))); - $this->assertFalse(is_countable(new \stdClass())); - - $endianBytes = unpack('S', "\x01\x00"); - if (1 === $endianBytes[1] && class_exists('ResourceBundle')) { // skip on big endian systems: the fixture is only for little endian ones - $this->assertTrue(is_countable(\ResourceBundle::create('en', __DIR__.'/fixtures'))); - } - } - - public function testIsCountableForGenerator() - { - require_once 'generator.php'; - - $this->assertFalse(is_countable(genOneToTen())); - } - - public function testHardwareTimeAsNumType() - { - $hrtime = hrtime(true); - if (\PHP_INT_SIZE === 4) { - $this->assertIsFloat($hrtime); - $this->assertEquals(floor($hrtime), $hrtime); - } else { - $this->assertIsInt($hrtime); - } - } - - public function testHardwareTimeAsNum() - { - $hrtime = hrtime(true); - usleep(100000); - $hrtime2 = hrtime(true); - - if (\PHP_INT_SIZE === 4) { - $this->assertGreaterThanOrEqual(90000000.0, $hrtime2 - $hrtime); - } else { - $this->assertGreaterThanOrEqual(100000000.0, $hrtime2 - $hrtime); - } - } - - public function testHardwareTimeAsArrayType() - { - $hrtime = hrtime(); - $this->assertIsArray($hrtime); - $this->assertCount(2, $hrtime); - $this->assertIsInt($hrtime[0]); - $this->assertIsInt($hrtime[1]); - } - - public function testHardwareTimeAsArrayNanos() - { - $hrtime = hrtime(); - usleep(1000); - $hrtime2 = hrtime(); - - $this->assertSame(0, $hrtime2[0] - $hrtime[0]); - $this->assertGreaterThanOrEqual(1000000, $hrtime2[1] - $hrtime[1]); - } - - public function testHardwareTimeAsArraySeconds() - { - $hrtime = hrtime(); - usleep(1000000); - $hrtime2 = hrtime(); - - $this->assertGreaterThanOrEqual(1, $hrtime2[0] - $hrtime[0]); - $this->assertGreaterThanOrEqual(0, $hrtime2[1] - $hrtime[1]); - } - - /** - * @dataProvider arrayKeyFirstDataProvider - */ - public function testArrayKeyFirst($expected, array $array) - { - $this->assertSame($expected, array_key_first($array)); - } - - public function testArrayKeyFirstVariation() - { - $array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - - $this->assertSame(1, current($array)); - $this->assertSame(2, next($array)); - $this->assertSame(0, array_key_first($array)); - $this->assertSame(2, current($array)); - } - - /** - * @dataProvider arrayKeyLastDataProvider - */ - public function testArrayLastFirst($expected, array $array) - { - $this->assertSame($expected, array_key_last($array)); - } - - public function testArrayKeyLastVariation() - { - $array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - - $this->assertSame(1, current($array)); - $this->assertSame(2, next($array)); - $this->assertSame(8, array_key_last($array)); - $this->assertSame(2, current($array)); - } - - public static function arrayKeyFirstDataProvider() - { - return [ - [null, []], - [0, [1, 2, 3, 4, 5, 6, 7, 8, 9]], - [0, ['One', '_Two', 'Three', 'Four', 'Five']], - [0, [6, 'six', 7, 'seven', 8, 'eight', 9, 'nine']], - ['a', ['a' => 'aaa', 'A' => 'AAA', 'c' => 'ccc', 'd' => 'ddd', 'e' => 'eee']], - [1, ['1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five']], - [1, [1 => 'one', 2 => 'two', 3 => 7, 4 => 'four', 5 => 'five']], - ['f', ['f' => 'fff', '1' => 'one', 4 => 6, '' => 'blank', 24 => 'float', 'F' => 'FFF', 'blank' => '', 3 => 3.7, 5 => 7, 6 => 8.6, '5' => 'Five', '4name' => 'jonny', 'a' => null, null => 3]], - [0, [12, 'name', 'age', '45']], - [0, [['oNe', 'tWo', 4], [10, 20, 30, 40, 50], []]], - ['one', ['one' => 1, 'one' => 2, 'three' => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, 5 => 54, 5 => 57, '5.4' => 554, '5.7' => 557]], - [0, ['foo']], - [1, [1 => '42']], - ]; - } - - public static function arrayKeyLastDataProvider() - { - return [ - [null, []], - [8, [1, 2, 3, 4, 5, 6, 7, 8, 9]], - [4, ['One', '_Two', 'Three', 'Four', 'Five']], - [7, [6, 'six', 7, 'seven', 8, 'eight', 9, 'nine']], - ['e', ['a' => 'aaa', 'A' => 'AAA', 'c' => 'ccc', 'd' => 'ddd', 'e' => 'eee']], - [5, ['1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five']], - [5, [1 => 'one', 2 => 'two', 3 => 7, 4 => 'four', 5 => 'five']], - ['a', ['f' => 'fff', '1' => 'one', 4 => 6, '' => 'blank', 2 => 'float', 'F' => 'FFF', 'blank' => '', 3 => 3.7, 5 => 7, 6 => 8.6, '5' => 'Five', '4name' => 'jonny', 'a' => null, null => 3]], - [3, [12, 'name', 'age', '45']], - [2, [['oNe', 'tWo', 4], [10, 20, 30, 40, 50], []]], - ['5.7', ['one' => 1, 'one' => 2, 'three' => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, 5 => 54, 5 => 57, '5.4' => 554, '5.7' => 557]], - [0, ['foo']], - [1, [1 => '42']], - ]; - } -} diff --git a/tests/Php73/fixtures/en.res b/tests/Php73/fixtures/en.res deleted file mode 100644 index 7c1f71eba1be16c117e695bce2cb820d1c587211..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 316 zcmX|-yG{c!5Jk@}phz?{&>^uBMJk9A8bn8cAR5FYN*5^(asraIMqY1`j_=t|qT*Ay zHV<3ZbMHJn9#?$!_erbd$u{Fstk}+ud|W}*6FU@cf01-r1L3BQVKd}11hZjko5)=q z?b?Q9XZ9ufz{I%5j=gu*)J#MB&+l93m^g3Z&pjhLSmCu{$SEVv#3F$fE4ISmXfl7! z{x@pYIg+ZDiU+BJ6TNsVGZsg%IEIJ6u?qRqoGIR;&$a3<)N9UTn(1Rt`8$Gof62Zp Rja})IidVYsTz_&P{SDiCG)Mpd diff --git a/tests/Php73/generator.php b/tests/Php73/generator.php deleted file mode 100644 index 8101b006a..000000000 --- a/tests/Php73/generator.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php73; - -function genOneToTen() -{ - for ($i = 1; $i <= 10; ++$i) { - yield $i; - } -} diff --git a/tests/Php74/Php74Test.php b/tests/Php74/Php74Test.php deleted file mode 100644 index 44a17c995..000000000 --- a/tests/Php74/Php74Test.php +++ /dev/null @@ -1,142 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php74; - -use PHPUnit\Framework\TestCase; - -/** - * @author Ion Bazan - */ -class Php74Test extends TestCase -{ - /** - * @covers \Symfony\Polyfill\Php74\Php74::get_mangled_object_vars - */ - public function testGetMangledObjectVarsOnObject() - { - $obj = new B(); - $obj->dyn = 5; - $obj->{'6'} = 6; - - $this->assertEqualsCanonicalizing([ - "\0".'Symfony\Polyfill\Tests\Php74\B'."\0".'priv' => 4, - 'pub' => 1, - "\0".'*'."\0".'prot' => 2, - "\0".'Symfony\Polyfill\Tests\Php74\A'."\0".'priv' => 3, - 'dyn' => 5, - 6 => 6, - ], get_mangled_object_vars($obj)); - } - - /** - * @covers \Symfony\Polyfill\Php74\Php74::get_mangled_object_vars - */ - public function testGetMangledObjectVarsOnArrayObject() - { - $ao = new AO(['x' => 'y']); - $ao->dyn = 2; - - $this->assertSame([ - "\0".'Symfony\Polyfill\Tests\Php74\AO'."\0".'priv' => 1, - 'dyn' => 2, - ], get_mangled_object_vars($ao)); - } - - /** - * @covers \Symfony\Polyfill\Php74\Php74::get_mangled_object_vars - * - * @requires PHP < 8 - */ - public function testGetMangledObjectVarsOnNonObject() - { - $this->assertNull(@get_mangled_object_vars(0)); - $this->assertNull(@get_mangled_object_vars(true)); - $this->assertNull(@get_mangled_object_vars('string')); - $this->expectWarning(); - $this->expectWarningMessage('expects parameter 1 to be object'); - get_mangled_object_vars(1); - } - - /** - * @covers \Symfony\Polyfill\Php74\Php74::password_algos - */ - public function testPasswordAlgos() - { - $algos = password_algos(); - - if (\defined('PASSWORD_BCRYPT')) { - $this->assertContains(\PASSWORD_BCRYPT, $algos); - } - - if (\defined('PASSWORD_ARGON2I')) { - $this->assertContains(\PASSWORD_ARGON2I, $algos); - } - - if (\defined('PASSWORD_ARGON2ID')) { - $this->assertContains(\PASSWORD_ARGON2ID, $algos); - } - } - - /** - * @covers \Symfony\Polyfill\Php74\Php74::mb_str_split - */ - public function testStrSplit() - { - $this->assertSame(['한', '국', '어'], mb_str_split('한국어')); - $this->assertSame(['по', 'бе', 'да'], mb_str_split('победа', 2)); - $this->assertSame(['źre', 'bię'], mb_str_split('źrebię', 3)); - $this->assertSame(['źr', 'ebi', 'ę'], mb_str_split('źrebię', 3, 'ASCII')); - $this->assertSame(['alpha', 'bet'], mb_str_split('alphabet', 5)); - $this->assertSame(['e', '́', '💩', '𐍈'], mb_str_split('é💩𐍈', 1, 'UTF-8')); - } - - /** - * @covers \Symfony\Polyfill\Php74\Php74::mb_str_split - * - * @requires PHP < 8 - */ - public function testStrSplitWithInvalidValues() - { - $this->assertSame([], mb_str_split('', 1, 'UTF-8')); - $this->assertFalse(@mb_str_split('победа', 0)); - $this->assertNull(@mb_str_split([], 0)); - - $this->expectWarning(); - $this->expectWarningMessage('The length of each segment must be greater than zero'); - mb_str_split('победа', 0); - } -} - -class A -{ - public $pub = 1; - protected $prot = 2; - private $priv = 3; -} - -#[\AllowDynamicProperties] -class B extends A -{ - private $priv = 4; -} - -#[\AllowDynamicProperties] -class AO extends \ArrayObject -{ - private $priv = 1; - - #[\ReturnTypeWillChange] - public function getFlags() - { - return self::ARRAY_AS_PROPS | self::STD_PROP_LIST; - } -} diff --git a/tests/Php80/Php80Test.php b/tests/Php80/Php80Test.php deleted file mode 100644 index daa59c691..000000000 --- a/tests/Php80/Php80Test.php +++ /dev/null @@ -1,322 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php80; - -use PHPUnit\Framework\TestCase; - -/** - * @author Ion Bazan - * @author Nico Oelgart - * - * @group legacy - */ -class Php80Test extends TestCase -{ - /** - * @covers \Symfony\Polyfill\Php80\Php80::fdiv - * - * @dataProvider fdivProvider - */ - public function testFdiv($expected, $divident, $divisor) - { - try { - $result = fdiv($divident, $divisor); - } catch (\DivisionByZeroError $e) { - $result = $expected; - } - $this->assertSame($expected, $result); - // Cast to string to detect negative zero "-0" - $this->assertSame((string) $expected, (string) $result); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::fdiv - * - * @dataProvider nanFdivProvider - */ - public function testFdivNan($divident, $divisor) - { - try { - $this->assertNan(fdiv($divident, $divisor)); - } catch (\DivisionByZeroError $e) { - $this->assertNan(\NAN); - } - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::fdiv - * - * @dataProvider invalidFloatProvider - */ - public function testFdivTypeError($divident, $divisor) - { - $this->expectException('TypeError'); - fdiv($divident, $divisor); - } - - public function testFilterValidateBool() - { - $this->assertTrue(\defined('FILTER_VALIDATE_BOOL')); - $this->assertSame(\FILTER_VALIDATE_BOOLEAN, \FILTER_VALIDATE_BOOL); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::preg_last_error_msg - */ - public function testPregNoError() - { - $this->assertSame('No error', preg_last_error_msg()); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::preg_last_error_msg - */ - public function testPregMalformedUtfError() - { - @preg_split('/a/u', "a\xff"); - $this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', preg_last_error_msg()); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::preg_last_error_msg - */ - public function testPregMalformedUtf8Offset() - { - @preg_match('/a/u', "\xE3\x82\xA2", $m, 0, 1); - $this->assertSame( - 'The offset did not correspond to the beginning of a valid UTF-8 code point', - preg_last_error_msg() - ); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::str_contains - */ - public function testStrContains() - { - $this->assertTrue(str_contains('abc', '')); - $this->assertTrue(str_contains('abc', null)); - $this->assertTrue(str_contains('abc', 'a')); - $this->assertTrue(str_contains('abc', 'bc')); - $this->assertTrue(str_contains('abc', 'abc')); - $this->assertTrue(str_contains('한국어', '국')); - $this->assertTrue(str_contains('한국어', '')); - $this->assertTrue(str_contains('', '')); - $this->assertFalse(str_contains('abc', 'd')); - $this->assertFalse(str_contains('', 'd')); - $this->assertFalse(str_contains(null, 'd')); - $this->assertFalse(str_contains('abc', 'abcd')); - $this->assertFalse(str_contains('DÉJÀ', 'à')); - $this->assertFalse(str_contains('a', 'à')); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::str_starts_with - */ - public function testStrStartsWith() - { - $testStr = 'beginningMiddleEnd'; - - $this->assertTrue(str_starts_with($testStr, 'beginning')); - $this->assertTrue(str_starts_with($testStr, $testStr)); - $this->assertTrue(str_starts_with($testStr, '')); - $this->assertTrue(str_starts_with($testStr, null)); - $this->assertTrue(str_starts_with('', '')); - $this->assertTrue(str_starts_with(null, '')); - $this->assertTrue(str_starts_with("\x00", '')); - $this->assertTrue(str_starts_with("\x00", "\x00")); - $this->assertTrue(str_starts_with("\x00a", "\x00")); - $this->assertTrue(str_starts_with("a\x00bc", "a\x00b")); - - $this->assertFalse(str_starts_with($testStr, 'Beginning')); - $this->assertFalse(str_starts_with($testStr, 'eginning')); - $this->assertFalse(str_starts_with($testStr, $testStr.$testStr)); - $this->assertFalse(str_starts_with('', ' ')); - $this->assertFalse(str_starts_with($testStr, "\x00")); - $this->assertFalse(str_starts_with("a\x00b", "a\x00d")); - $this->assertFalse(str_starts_with("a\x00b", "z\x00b")); - $this->assertFalse(str_starts_with('a', "a\x00")); - $this->assertFalse(str_starts_with('a', "\x00a")); - - // අයේෂ් = අ + ය + "ේ" + ෂ + ් - // අයේෂ් = (0xe0 0xb6 0x85) + (0xe0 0xb6 0xba) + (0xe0 0xb7 0x9a) + (0xe0 0xb7 0x82) + (0xe0 0xb7 0x8a) - $testMultiByte = 'අයේෂ්'; // 0xe0 0xb6 0x85 0xe0 0xb6 0xba 0xe0 0xb7 0x9a 0xe0 0xb7 0x82 0xe0 0xb7 0x8a - $this->assertTrue(str_starts_with($testMultiByte, 'අයේ')); // 0xe0 0xb6 0x85 0xe0 0xb6 0xba 0xe0 0xb7 0x9a - $this->assertTrue(str_starts_with($testMultiByte, 'අය')); // 0xe0 0xb6 0x85 0xe0 0xb6 0xba - $this->assertFalse(str_starts_with($testMultiByte, 'ය')); // 0xe0 0xb6 0xba - $this->assertFalse(str_starts_with($testMultiByte, 'අේ')); // 0xe0 0xb6 0x85 0xe0 0xb7 0x9a - - $testEmoji = '🙌🎉✨🚀'; // 0xf0 0x9f 0x99 0x8c 0xf0 0x9f 0x8e 0x89 0xe2 0x9c 0xa8 0xf0 0x9f 0x9a 0x80 - $this->assertTrue(str_starts_with($testEmoji, '🙌')); // 0xf0 0x9f 0x99 0x8c - $this->assertFalse(str_starts_with($testEmoji, '✨')); // 0xe2 0x9c 0xa8 - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::str_ends_with - */ - public function testStrEndsWith() - { - $testStr = 'beginningMiddleEnd'; - - $this->assertTrue(str_ends_with($testStr, 'End')); - $this->assertFalse(str_ends_with($testStr, 'end')); - $this->assertFalse(str_ends_with($testStr, 'en')); - $this->assertTrue(str_ends_with($testStr, $testStr)); - $this->assertFalse(str_ends_with($testStr, $testStr.$testStr)); - $this->assertTrue(str_ends_with($testStr, '')); - $this->assertTrue(str_ends_with($testStr, null)); - $this->assertTrue(str_ends_with('', '')); - $this->assertTrue(str_ends_with(null, '')); - $this->assertFalse(str_ends_with('', ' ')); - $this->assertFalse(str_ends_with($testStr, "\x00")); - $this->assertTrue(str_ends_with("\x00", '')); - $this->assertTrue(str_ends_with("\x00", "\x00")); - $this->assertTrue(str_ends_with("a\x00", "\x00")); - $this->assertTrue(str_ends_with("ab\x00c", "b\x00c")); - $this->assertFalse(str_ends_with("a\x00b", "d\x00b")); - $this->assertFalse(str_ends_with("a\x00b", "a\x00z")); - $this->assertFalse(str_ends_with('a', "\x00a")); - $this->assertFalse(str_ends_with('a', "a\x00")); - - $testMultiByte = 'අයේෂ්'; // 0xe0 0xb6 0x85 0xe0 0xb6 0xba 0xe0 0xb7 0x9a 0xe0 0xb7 0x82 0xe0 0xb7 0x8a - $this->assertTrue(str_ends_with($testMultiByte, 'ෂ්')); // 0xe0 0xb7 0x82 0xe0 0xb7 0x8a - $this->assertTrue(str_ends_with($testMultiByte, '්')); // 0xe0 0xb7 0x8a - $this->assertFalse(str_ends_with($testMultiByte, 'ෂ')); // 0xe0 0xb7 0x82 - - $testEmoji = '🙌🎉✨🚀'; // 0xf0 0x9f 0x99 0x8c 0xf0 0x9f 0x8e 0x89 0xe2 0x9c 0xa8 0xf0 0x9f 0x9a 0x80 - $this->assertTrue(str_ends_with($testEmoji, '🚀')); // 0xf0 0x9f 0x9a 0x80 - $this->assertFalse(str_ends_with($testEmoji, '✨')); // 0xe2 0x9c 0xa8 - - $this->assertFalse(str_ends_with('', '[]')); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::get_resource_id - */ - public function testGetResourceIdWithValidResource() - { - $resource = fopen(__FILE__, 'r'); - $resourceId = (int) $resource; - $this->assertSame($resourceId, get_resource_id($resource)); - fclose($resource); - $this->assertSame($resourceId, get_resource_id($resource)); - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::get_resource_id - * - * @dataProvider invalidResourceProvider - */ - public function testGetResourceWithInvalidValue($value) - { - $this->expectException('TypeError'); - get_resource_id($value); - } - - public static function fdivProvider() - { - return [ - [10 / 3, '10', '3'], - [10 / 3, 10.0, 3.0], - [-4.0, -10.0, 2.5], - [-4.0, 10.0, -2.5], - [\INF, 10.0, 0.0], - [-\INF, 10.0, -0.0], - [-\INF, -10.0, 0.0], - [\INF, -10.0, -0.0], - [\INF, \INF, 0.0], - [-\INF, \INF, -0.0], - [-\INF, -\INF, 0.0], - [\INF, -\INF, -0.0], - [0.0, 0.0, \INF], - [-0.0, 0.0, -\INF], - [-0.0, -0.0, \INF], - [0.0, -0.0, -\INF], - ]; - } - - public static function nanFdivProvider() - { - return [ - [0.0, 0.0], - [0.0, -0.0], - [-0.0, 0.0], - [-0.0, -0.0], - [\INF, \INF], - [\INF, -\INF], - [-\INF, \INF], - [-\INF, -\INF], - [\NAN, \NAN], - [\INF, \NAN], - [-0.0, \NAN], - [\NAN, \INF], - [\NAN, 0.0], - ]; - } - - public static function invalidFloatProvider() - { - return [ - ['invalid', 1.0], - ['invalid', 'invalid'], - [1.0, 'invalid'], - ]; - } - - public static function invalidResourceProvider() - { - return [ - [true], - [null], - [new \stdClass()], - ['test'], - [10], - [10.0], - ]; - } - - /** - * @covers \Symfony\Polyfill\Php80\Php80::get_debug_type - */ - public function testGetDebugType() - { - $this->assertSame(__CLASS__, get_debug_type($this)); - $this->assertSame('stdClass', get_debug_type(new \stdClass())); - $this->assertSame('class@anonymous', get_debug_type(eval('return new class() {};'))); - $this->assertSame('stdClass@anonymous', get_debug_type(eval('return new class() extends stdClass {};'))); - $this->assertSame('Reflector@anonymous', get_debug_type(eval('return new class() implements Reflector { function __toString() {} public static function export() {} };'))); - - $this->assertSame('string', get_debug_type('foo')); - $this->assertSame('bool', get_debug_type(false)); - $this->assertSame('bool', get_debug_type(true)); - $this->assertSame('null', get_debug_type(null)); - $this->assertSame('array', get_debug_type([])); - $this->assertSame('int', get_debug_type(1)); - $this->assertSame('float', get_debug_type(1.2)); - $this->assertSame('resource (stream)', get_debug_type($h = fopen(__FILE__, 'r'))); - $this->assertSame('resource (closed)', get_debug_type(fclose($h) ? $h : $h)); - - $unserializeCallbackHandler = ini_set('unserialize_callback_func', null); - $var = unserialize('O:8:"Foo\Buzz":0:{}'); - ini_set('unserialize_callback_func', $unserializeCallbackHandler); - - $this->assertSame('__PHP_Incomplete_Class', get_debug_type($var)); - } - - public function testAttributePolyfill() - { - $attribute = new \Attribute(); - $this->assertSame(\Attribute::TARGET_ALL, $attribute->flags); - $attribute = new \Attribute(\Attribute::TARGET_CLASS); - $this->assertSame(\Attribute::TARGET_CLASS, $attribute->flags); - } -} diff --git a/tests/Php80/PhpTokenTest.php b/tests/Php80/PhpTokenTest.php deleted file mode 100644 index b8a54de98..000000000 --- a/tests/Php80/PhpTokenTest.php +++ /dev/null @@ -1,83 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php80; - -use PHPUnit\Framework\TestCase; -use Symfony\Polyfill\Php80\PhpToken as PhpTokenPolyfill; - -class PhpTokenTest extends TestCase -{ - public function testTokenize() - { - $code = file_get_contents(__FILE__); - $tokens = \PhpToken::tokenize($code); - $polyfillTokens = PhpTokenPolyfill::tokenize($code); - $this->assertEqualsCanonicalizing((array) $tokens[1], (array) $polyfillTokens[1]); - $this->assertEqualsCanonicalizing((array) $tokens[50], (array) $polyfillTokens[50]); - $this->assertEqualsCanonicalizing((array) $tokens[100], (array) $polyfillTokens[100]); - $this->assertEqualsCanonicalizing((array) $tokens[150], (array) $polyfillTokens[150]); - $this->assertEqualsCanonicalizing((array) $tokens[200], (array) $polyfillTokens[200]); - $this->assertEqualsCanonicalizing((array) $tokens[250], (array) $polyfillTokens[250]); - } - - public function testGetTokenName() - { - // named token - $token = new \PhpToken(\T_ECHO, 'echo'); - $polyfillToken = new PhpTokenPolyfill(\T_ECHO, 'echo'); - $this->assertSame($token->getTokenName(), $polyfillToken->getTokenName()); - // single char token - $token = new \PhpToken(\ord(';'), ';'); - $polyfillToken = new PhpTokenPolyfill(\ord(';'), ';'); - $this->assertSame($token->getTokenName(), $polyfillToken->getTokenName()); - // unknown token - $token = new \PhpToken(10000, "\0"); - $polyfillToken = new PhpTokenPolyfill(10000, "\0"); - $this->assertSame($token->getTokenName(), $polyfillToken->getTokenName()); - } - - public function testIs() - { - // single token - $token = new \PhpToken(\T_ECHO, 'echo'); - $polyfillToken = new PhpTokenPolyfill(\T_ECHO, 'echo'); - $this->assertSame($token->is(\T_ECHO), $polyfillToken->is(\T_ECHO)); - $this->assertSame($token->is('echo'), $polyfillToken->is('echo')); - $this->assertSame($token->is('T_ECHO'), $polyfillToken->is('T_ECHO')); - // token set - $token = new \PhpToken(\T_TRAIT, 'trait'); - $polyfillToken = new PhpTokenPolyfill(\T_TRAIT, 'trait'); - $this->assertSame( - $token->is([\T_INTERFACE, \T_CLASS, \T_TRAIT]), - $polyfillToken->is([\T_INTERFACE, \T_CLASS, \T_TRAIT]) - ); - // mixed set - $token = new \PhpToken(\T_TRAIT, 'trait'); - $polyfillToken = new PhpTokenPolyfill(\T_TRAIT, 'trait'); - $this->assertSame( - $token->is([\T_INTERFACE, 'class', 334]), - $polyfillToken->is([\T_INTERFACE, 'class', 334]) - ); - } - - public function testIsIgnorable() - { - // not ignorable token - $token = new \PhpToken(\T_ECHO, 'echo'); - $polyfillToken = new PhpTokenPolyfill(\T_ECHO, 'echo'); - $this->assertSame($token->isIgnorable(), $polyfillToken->isIgnorable()); - // ignorable token - $token = new \PhpToken(\T_COMMENT, '// todo'); - $polyfillToken = new PhpTokenPolyfill(\T_COMMENT, '// todo'); - $this->assertSame($token->isIgnorable(), $polyfillToken->isIgnorable()); - } -} diff --git a/tests/Php81/CURLStringFileTest.php b/tests/Php81/CURLStringFileTest.php deleted file mode 100644 index d800c9c5d..000000000 --- a/tests/Php81/CURLStringFileTest.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php81; - -use PHPUnit\Framework\TestCase; - -/** - * @requires extension curl - * @requires PHP 7.4 - */ -class CURLStringFileTest extends TestCase -{ - private static $server; - - public static function setUpBeforeClass(): void - { - $spec = [ - 1 => ['file', '/dev/null', 'w'], - 2 => ['file', '/dev/null', 'w'], - ]; - if (!self::$server = @proc_open(('\\' === \DIRECTORY_SEPARATOR ? '' : 'exec ').\PHP_BINARY.' -S localhost:8086', $spec, $pipes, __DIR__.'/fixtures')) { - self::markTestSkipped('Unable to start PHP server.'); - } - sleep(1); - } - - public static function tearDownAfterClass(): void - { - if (self::$server) { - proc_terminate(self::$server); - proc_close(self::$server); - } - } - - public function testCurlFileShowsContents() - { - $file = new \CURLStringFile('Hello', 'symfony.txt', 'text/plain'); - $data = ['test_file' => $file]; - - $ch = curl_init('http://localhost:8086/curl-echo-server.php'); - - curl_setopt($ch, \CURLOPT_POST, 1); - curl_setopt($ch, \CURLOPT_POSTFIELDS, $data); - curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($ch); - - $this->assertEquals(200, curl_getinfo($ch, \CURLINFO_HTTP_CODE)); - $this->assertSame('{"test_file":{"name":"symfony.txt","type":"text\/plain","error":0,"size":5}}', $response); - } -} diff --git a/tests/Php81/Php81Test.php b/tests/Php81/Php81Test.php deleted file mode 100644 index 8047528cd..000000000 --- a/tests/Php81/Php81Test.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Polyfill\Tests\Php81; - -use PHPUnit\Framework\TestCase; - -class Php81Test extends TestCase -{ - /** - * @covers \Symfony\Polyfill\Php81\Php81::array_is_list - */ - public function testArrayIsList() - { - $this->assertTrue(array_is_list([])); - $this->assertTrue(array_is_list([\NAN, 'foo', 123])); - $this->assertFalse(array_is_list([1 => 'a', 0 => 'b'])); - $this->assertFalse(array_is_list(['a' => 'b'])); - $this->assertFalse(array_is_list([0 => 'a', 2 => 'b'])); - $this->assertFalse(array_is_list([1 => 'a', 2 => 'b'])); - - $x = ['key' => 2, \NAN]; - unset($x['key']); - $this->assertTrue(array_is_list($x)); - } - - /** - * @requires extension mysqli - * @group legacy - */ - public function testMysqliRefreshReplicaDefined() - { - $this->assertTrue(\defined('MYSQLI_REFRESH_REPLICA')); - $this->assertSame(MYSQLI_REFRESH_SLAVE, MYSQLI_REFRESH_REPLICA); - } -} diff --git a/tests/Php81/fixtures/curl-echo-server.php b/tests/Php81/fixtures/curl-echo-server.php deleted file mode 100644 index 2221c5c2a..000000000 --- a/tests/Php81/fixtures/curl-echo-server.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -$output = $_FILES; -foreach ($_FILES as $name => $file) { - if (is_string($file['tmp_name'] ?? null)) { - unset($file['tmp_name'], $file['full_path']); - $output[$name] = $file; - } -} -echo json_encode($output); diff --git a/tests/Php82/Php82Test.php b/tests/Php82/Php82Test.php index f0104a2af..8892b83e9 100644 --- a/tests/Php82/Php82Test.php +++ b/tests/Php82/Php82Test.php @@ -347,12 +347,6 @@ public function testIniParseQuantitySpecialCharactersAreEscaped() */ public function testIniParseQuantityUsingBruteForce() { - if (\PHP_VERSION_ID < 80200) { - $this->markTestSkipped('This test requires the PHP function as a reference.'); - - return; - } - // Comment these lines to run the tests. $this->markTestSkipped('This test is slow and should only be used for local development.'); diff --git a/tests/Php84/Php84Test.php b/tests/Php84/Php84Test.php index 9d573a186..24525fd24 100644 --- a/tests/Php84/Php84Test.php +++ b/tests/Php84/Php84Test.php @@ -95,7 +95,7 @@ public static function ucFirstDataProvider(): array ['łámał', 'Łámał'], // Full case-mapping and case-folding that changes the length of the string only supported // in PHP > 7.3. - ['ßst', \PHP_VERSION_ID < 70300 ? 'ßst' : 'Ssst'], + ['ßst', 'Ssst'], ]; } @@ -110,8 +110,8 @@ public static function lcFirstDataProvider(): array ['ABS', 'aBS'], ['Đắt quá!', 'đắt quá!'], ['აბგ', 'აბგ'], - ['Lj', \PHP_VERSION_ID < 70200 ? 'Lj' : 'lj'], - ["\u{01CB}", \PHP_VERSION_ID < 70200 ? "\u{01CB}" : "\u{01CC}"], + ['Lj', 'lj'], + ["\u{01CB}", "\u{01CC}"], ["\u{01CA}", "\u{01CC}"], ["\u{01CA}\u{01CA}", "\u{01CC}\u{01CA}"], ["\u{212A}\u{01CA}", "\u{006b}\u{01CA}"], diff --git a/tests/Uuid/UuidTest.php b/tests/Uuid/UuidTest.php index c84bef9fc..711bef825 100644 --- a/tests/Uuid/UuidTest.php +++ b/tests/Uuid/UuidTest.php @@ -41,12 +41,10 @@ public function testGenerateMd5() public function testGenerateMd5WithInvalidUuid() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_generate_md5(): Argument #1 ($uuid_ns) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_generate_md5(): Argument #1 ($uuid_ns) UUID expected'); - $this->assertFalse(@uuid_generate_md5('not a uuid', 'foo')); + @uuid_generate_md5('not a uuid', 'foo'); } public function testGenerateSha1() @@ -68,12 +66,10 @@ public function testGenerateSha1() public function testGenerateSha1WithInvalidUuid() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_generate_sha1(): Argument #1 ($uuid_ns) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_generate_sha1(): Argument #1 ($uuid_ns) UUID expected'); - $this->assertFalse(@uuid_generate_sha1('not a uuid', 'foo')); + @uuid_generate_sha1('not a uuid', 'foo'); } public static function provideCreateNoOverlapTests(): array @@ -140,22 +136,18 @@ public function testCompare(int $expected, string $uuid1, string $uuid2) public function testCompareWithInvalidUuidLeft() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_compare(): Argument #1 ($uuid1) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_compare(): Argument #1 ($uuid1) UUID expected'); - $this->assertFalse(@uuid_compare('foobar', 'fa83b381-328c-46b8-8c90-4e9ba47dfa4b')); + @uuid_compare('foobar', 'fa83b381-328c-46b8-8c90-4e9ba47dfa4b'); } public function testCompareWithInvalidUuidRight() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_compare(): Argument #2 ($uuid2) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_compare(): Argument #2 ($uuid2) UUID expected'); - $this->assertFalse(@uuid_compare('fa83b381-328c-46b8-8c90-4e9ba47dfa4b', 'foobar')); + @uuid_compare('fa83b381-328c-46b8-8c90-4e9ba47dfa4b', 'foobar'); } public static function provideIsNullTest(): array @@ -175,12 +167,10 @@ public function testIsNull(bool $expected, string $uuid) public function testIsNullWithInvalidUuid() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_is_null(): Argument #1 ($uuid) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_is_null(): Argument #1 ($uuid) UUID expected'); - $this->assertFalse(@uuid_is_null('foobar')); + @uuid_is_null('foobar'); } public static function provideTypeTest(): array @@ -201,12 +191,10 @@ public function testType(int $expected, string $uuid) public function testTypeWithInvalidUuid() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_type(): Argument #1 ($uuid) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_type(): Argument #1 ($uuid) UUID expected'); - $this->assertFalse(@uuid_type('foobar')); + @uuid_type('foobar'); } public static function provideVariantTest(): array @@ -226,12 +214,10 @@ public function testVariant(int $expected, string $uuid) public function testVariantWithInvalidUuid() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_variant(): Argument #1 ($uuid) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_variant(): Argument #1 ($uuid) UUID expected'); - $this->assertFalse(@uuid_variant('foobar')); + @uuid_variant('foobar'); } public static function provideTimeTest(): array @@ -262,12 +248,10 @@ public static function provideInvalidTimeTest(): array */ public function testTimeWithInvalidUuid(string $uuid) { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_time(): Argument #1 ($uuid) UUID DCE TIME expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_time(): Argument #1 ($uuid) UUID DCE TIME expected'); - $this->assertFalse(@uuid_time($uuid)); + @uuid_time($uuid); } public static function provideMacTest(): array @@ -298,12 +282,10 @@ public static function provideInvalidMacTest(): array */ public function testMacWithInvalidUuid(string $uuid) { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_mac(): Argument #1 ($uuid) UUID DCE TIME expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_mac(): Argument #1 ($uuid) UUID DCE TIME expected'); - $this->assertFalse(@uuid_mac($uuid)); + @uuid_mac($uuid); } public static function provideParseTest(): array @@ -325,12 +307,10 @@ public function testParse(string $expected, string $uuid) public function testParseWithInvalidUuid() { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_parse(): Argument #1 ($uuid) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_parse(): Argument #1 ($uuid) UUID expected'); - $this->assertFalse(@uuid_parse('foobar')); + @uuid_parse('foobar'); } public static function provideUnparseTest(): array @@ -361,11 +341,9 @@ public static function provideInvalidUnparseTest(): array */ public function testUnparseWithInvalidUuid(string $uuid) { - if (80000 <= \PHP_VERSION_ID) { - $this->expectException(\ValueError::class); - $this->expectExceptionMessage('uuid_unparse(): Argument #1 ($uuid) UUID expected'); - } + $this->expectException(\ValueError::class); + $this->expectExceptionMessage('uuid_unparse(): Argument #1 ($uuid) UUID expected'); - $this->assertFalse(@uuid_unparse($uuid)); + @uuid_unparse($uuid); } }