forked from getsentry/sentry-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventHandlerTest.php
50 lines (38 loc) · 1.3 KB
/
EventHandlerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Sentry\Laravel\Tests\Tracing;
use ReflectionClass;
use RuntimeException;
use Sentry\Laravel\Tests\TestCase;
use Sentry\Laravel\Tracing\EventHandler;
class EventHandlerTest extends TestCase
{
public function testMissingEventHandlerThrowsException(): void
{
$this->expectException(RuntimeException::class);
$handler = new EventHandler([]);
/** @noinspection PhpUndefinedMethodInspection */
$handler->thisIsNotAHandlerAndShouldThrowAnException();
}
public function testAllMappedEventHandlersExist(): void
{
$this->tryAllEventHandlerMethods(
$this->getEventHandlerMapFromEventHandler()
);
}
private function tryAllEventHandlerMethods(array $methods): void
{
$handler = new EventHandler([]);
$methods = array_map(static function ($method) {
return "{$method}Handler";
}, array_unique(array_values($methods)));
foreach ($methods as $handlerMethod) {
$this->assertTrue(method_exists($handler, $handlerMethod));
}
}
private function getEventHandlerMapFromEventHandler()
{
$class = new ReflectionClass(EventHandler::class);
$attributes = $class->getStaticProperties();
return $attributes['eventHandlerMap'];
}
}