Skip to content

Commit 3def05b

Browse files
staabmsebastianbergmann
authored andcommitted
Prevent fatal errors not reported
happens when php.ini declares `display_errors=0`
1 parent f00723c commit 3def05b

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

src/Framework/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ private function runTest(): mixed
12971297

12981298
$capture = tmpfile();
12991299
assert($capture !== false);
1300+
ini_set('display_errors', 1);
13001301
$errorLogPrevious = ini_set('error_log', stream_get_meta_data($capture)['uri']);
13011302

13021303
try {

tests/end-to-end/regression/6294.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Silent failure of PHP fatal errors
3+
4+
https://github.com/sebastianbergmann/phpunit/issues/6294
5+
--INI--
6+
display_errors=0
7+
--FILE--
8+
<?php declare(strict_types=1);
9+
$_SERVER['argv'][] = '--do-not-cache-result';
10+
$_SERVER['argv'][] = '--no-configuration';
11+
$_SERVER['argv'][] = __DIR__ . '/6294/IssueTest6294.php';
12+
13+
require_once __DIR__ . '/../../bootstrap.php';
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit %s by Sebastian Bergmann and contributors.
17+
18+
Runtime: %s
19+
20+
21+
Fatal error: Access level to B::someFunction() must be public (as in class A) in %sB.php on line %i
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
class A
11+
{
12+
public function someFunction(): void
13+
{
14+
print 'A::someFunction' . \PHP_EOL;
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
class B extends A
11+
{
12+
// incorrect access level
13+
protected function someFunction(): void
14+
{
15+
parent::someFunction();
16+
17+
print 'B::someFunction' . \PHP_EOL;
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
use PHPUnit\Framework\TestCase;
11+
12+
final class IssueTest6294 extends TestCase
13+
{
14+
public function testOne(): void
15+
{
16+
require_once 'A.php';
17+
18+
require_once 'B.php';
19+
20+
$this->assertSame(1, 1);
21+
}
22+
}

0 commit comments

Comments
 (0)