Skip to content

Commit 24a17a6

Browse files
Merge branch '12.3'
2 parents 5645575 + 96e34ea commit 24a17a6

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-0
lines changed

src/Framework/TestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use function getcwd;
2727
use function implode;
2828
use function in_array;
29+
use function ini_get;
2930
use function ini_set;
3031
use function is_array;
3132
use function is_callable;
@@ -83,6 +84,7 @@
8384
use PHPUnit\Runner\BackedUpEnvironmentVariable;
8485
use PHPUnit\Runner\DeprecationCollector\Facade as DeprecationCollector;
8586
use PHPUnit\Runner\HookMethodCollection;
87+
use PHPUnit\Runner\ShutdownHandler;
8688
use PHPUnit\TestRunner\TestResult\PassedTests;
8789
use PHPUnit\TextUI\Configuration\Registry as ConfigurationRegistry;
8890
use PHPUnit\Util\Exporter;
@@ -1297,6 +1299,10 @@ private function runTest(): mixed
12971299

12981300
$capture = tmpfile();
12991301
assert($capture !== false);
1302+
1303+
if (ini_get('display_errors') === '0') {
1304+
ShutdownHandler::setMessage('Fatal error: Premature end of PHP process. Use display_errors=On to see the error message.');
1305+
}
13001306
$errorLogPrevious = ini_set('error_log', stream_get_meta_data($capture)['uri']);
13011307

13021308
try {
@@ -1331,6 +1337,7 @@ private function runTest(): mixed
13311337

13321338
return null;
13331339
} finally {
1340+
ShutdownHandler::resetMessage();
13341341
fclose($capture);
13351342

13361343
ini_set('error_log', $errorLogPrevious);

src/Runner/ShutdownHandler.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\Runner;
11+
12+
use function register_shutdown_function;
13+
14+
/**
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
16+
*
17+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
18+
*/
19+
final class ShutdownHandler
20+
{
21+
private static bool $registered = false;
22+
private static string $message = '';
23+
24+
public static function setMessage(string $message): void
25+
{
26+
self::register();
27+
28+
self::$message = $message;
29+
}
30+
31+
public static function resetMessage(): void
32+
{
33+
self::$message = '';
34+
}
35+
36+
private static function register(): void
37+
{
38+
if (self::$registered) {
39+
return;
40+
}
41+
42+
register_shutdown_function(static function (): void
43+
{
44+
print self::$message;
45+
});
46+
}
47+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6294
3+
--INI--
4+
display_errors=0
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/6294/IssueTest6294.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit %s by Sebastian Bergmann and contributors.
15+
16+
Runtime: %s
17+
18+
Fatal error: Premature end of PHP process. Use display_errors=On to see the error message.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6294
3+
--INI--
4+
display_errors=1
5+
--FILE--
6+
<?php declare(strict_types=1);
7+
$_SERVER['argv'][] = '--do-not-cache-result';
8+
$_SERVER['argv'][] = '--no-configuration';
9+
$_SERVER['argv'][] = __DIR__ . '/6294/IssueTest6294.php';
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit %s by Sebastian Bergmann and contributors.
15+
16+
Runtime: %s
17+
18+
19+
Fatal error: Access level to PHPUnit\TestFixture\B::someFunction() must be public (as in class PHPUnit\TestFixture\A) in %sB.php on line %i%A
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use const PHP_EOL;
13+
14+
class A
15+
{
16+
public function someFunction(): void
17+
{
18+
print 'A::someFunction' . PHP_EOL;
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use const PHP_EOL;
13+
14+
class B extends A
15+
{
16+
// incorrect access level
17+
protected function someFunction(): void
18+
{
19+
parent::someFunction();
20+
21+
print 'B::someFunction' . PHP_EOL;
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class IssueTest6294 extends TestCase
15+
{
16+
public function testOne(): void
17+
{
18+
require_once 'A.php';
19+
20+
require_once 'B.php';
21+
22+
$this->assertSame(1, 1);
23+
}
24+
}

0 commit comments

Comments
 (0)