Skip to content

Instantly share code, notes, and snippets.

@ghostwriter
Created August 25, 2023 03:14
Show Gist options
  • Save ghostwriter/7a45ffbba8ac2746175a4e82a5d22d79 to your computer and use it in GitHub Desktop.
Save ghostwriter/7a45ffbba8ac2746175a4e82a5d22d79 to your computer and use it in GitHub Desktop.
#PHPUnit `expect*()` replacement.
<?php
declare(strict_types=1);
namespace Foo\Tests\Unit;
final class FooTest extends TestCase
{
public function testFoo(): void
{
set_error_handler(
static function (int $errno, string $errstr ) {
restore_error_handler();
throw new \Exception( $errstr, $errno );
},
E_ALL
);
$this->expectException(\Exception::class);
$this->expectExceptionMessageMatches('Expected Warning/Error/Deprecation message');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment