Skip to content

Commit 731f6e1

Browse files
minor #495 Give testing some love (nicolas-grekas)
This PR was merged into the 1.x branch. Discussion ---------- Give testing some love `./phpunit` FTW + some goodies Commits ------- 1c3f8e8 Give testing some love
2 parents 2ae3bda + 1c3f8e8 commit 731f6e1

18 files changed

+111
-67
lines changed

.github/workflows/tests.yml

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

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

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

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

.gitignore

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

appveyor.yml

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

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

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

phpunit

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

src/Apcu/bootstrap80.php

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

src/Intl/Idn/Idn.php

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

src/Mbstring/bootstrap80.php

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

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

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

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

src/Php84/bootstrap.php

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

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

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

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

src/Util/TestListenerForV7.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
*/
2424
class TestListenerForV7 extends TestSuite implements TestListenerInterface
2525
{
26-
private $suite;
2726
private $trait;
2827

2928
public function __construct(?TestSuite $suite = null)
3029
{
3130
if ($suite) {
32-
$this->suite = $suite;
3331
$this->setName($suite->getName().' with polyfills enabled');
3432
$this->addTest($suite);
3533
}
@@ -38,7 +36,13 @@ public function __construct(?TestSuite $suite = null)
3836

3937
public function startTestSuite(TestSuite $suite): void
4038
{
41-
$this->trait->startTestSuite($suite);
39+
if (null === TestListenerTrait::$enabledPolyfills) {
40+
TestListenerTrait::$enabledPolyfills = false;
41+
$this->trait->startTestSuite($suite);
42+
}
43+
if ($suite instanceof TestListener) {
44+
TestListenerTrait::$enabledPolyfills = $suite->getName();
45+
}
4246
}
4347

4448
public function addError(Test $test, \Throwable $t, float $time): void
@@ -69,6 +73,7 @@ public function addSkippedTest(Test $test, \Throwable $t, float $time): void
6973

7074
public function endTestSuite(TestSuite $suite): void
7175
{
76+
TestListenerTrait::$enabledPolyfills = false;
7277
}
7378

7479
public function startTest(Test $test): void
@@ -83,14 +88,4 @@ public static function warning($message): WarningTestCase
8388
{
8489
return new WarningTestCase($message);
8590
}
86-
87-
protected function setUp(): void
88-
{
89-
TestListenerTrait::$enabledPolyfills = $this->suite->getName();
90-
}
91-
92-
protected function tearDown(): void
93-
{
94-
TestListenerTrait::$enabledPolyfills = false;
95-
}
9691
}

src/Util/TestListenerForV9.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
class TestListenerForV9 extends TestSuite implements TestListenerInterface
2222
{
23-
private $suite;
2423
private $trait;
2524

2625
public function __construct(?TestSuite $suite = null)
2726
{
2827
if ($suite) {
29-
$this->suite = $suite;
3028
$this->setName($suite->getName().' with polyfills enabled');
3129
$this->addTest($suite);
3230
}
@@ -35,7 +33,13 @@ public function __construct(?TestSuite $suite = null)
3533

3634
public function startTestSuite(TestSuite $suite): void
3735
{
38-
$this->trait->startTestSuite($suite->tests()[0]);
36+
if (null === TestListenerTrait::$enabledPolyfills) {
37+
TestListenerTrait::$enabledPolyfills = false;
38+
$this->trait->startTestSuite($suite);
39+
}
40+
if ($suite instanceof TestListener) {
41+
TestListenerTrait::$enabledPolyfills = $suite->getName();
42+
}
3943
}
4044

4145
public function addError(Test $test, \Throwable $t, float $time): void
@@ -69,6 +73,7 @@ public function addSkippedTest(Test $test, \Throwable $t, float $time): void
6973

7074
public function endTestSuite(TestSuite $suite): void
7175
{
76+
TestListenerTrait::$enabledPolyfills = false;
7277
}
7378

7479
public function startTest(Test $test): void
@@ -83,14 +88,4 @@ public static function warning($message): WarningTestCase
8388
{
8489
return new WarningTestCase($message);
8590
}
86-
87-
protected function setUp(): void
88-
{
89-
TestListenerTrait::$enabledPolyfills = $this->suite->getName();
90-
}
91-
92-
protected function tearDown(): void
93-
{
94-
TestListenerTrait::$enabledPolyfills = false;
95-
}
9691
}

0 commit comments

Comments
 (0)