Skip to content

Commit 959fed0

Browse files
Import (and adapt) test case from jrfnl/bug-report-reproduction-scenarios@b3d9366
1 parent c2c8dbb commit 959fed0

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
4+
bootstrap="src/Foo.php"
5+
displayDetailsOnTestsThatTriggerErrors="true"
6+
displayDetailsOnTestsThatTriggerWarnings="true"
7+
displayDetailsOnTestsThatTriggerNotices="true"
8+
displayDetailsOnTestsThatTriggerDeprecations="true">
9+
<testsuites>
10+
<testsuite name="default">
11+
<directory>tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
</phpunit>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
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\Event\ErrorHandlerCanBeDisabled;
11+
12+
use function error_get_last;
13+
use function fopen;
14+
use function trigger_error;
15+
use Exception;
16+
17+
final class Foo
18+
{
19+
public function methodA($fileName)
20+
{
21+
$stream_handle = @fopen($fileName, 'wb');
22+
23+
if ($stream_handle === false) {
24+
$error = error_get_last();
25+
26+
throw new Exception($error['message']);
27+
}
28+
29+
return $stream_handle;
30+
}
31+
32+
public function methodB(): ?array
33+
{
34+
@trigger_error('Triggering', E_USER_WARNING);
35+
36+
return error_get_last();
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
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\Event\ErrorHandlerCanBeDisabled;
11+
12+
use function sys_get_temp_dir;
13+
use function tempnam;
14+
use Exception;
15+
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
16+
use PHPUnit\Framework\TestCase;
17+
18+
final class FooTest extends TestCase
19+
{
20+
#[WithoutErrorHandler]
21+
public function testMethodA(): void
22+
{
23+
$fileName = tempnam(sys_get_temp_dir(), 'RLT') . '/missing/directory';
24+
25+
$this->expectException(Exception::class);
26+
$this->expectExceptionMessage('Failed to open stream');
27+
28+
(new Foo)->methodA($fileName);
29+
}
30+
31+
#[WithoutErrorHandler]
32+
public function testMethodB(): void
33+
{
34+
$this->assertSame('Triggering', (new Foo)->methodB()['message']);
35+
}
36+
}

0 commit comments

Comments
 (0)