|
2 | 2 |
|
3 | 3 | namespace Sentry\Laravel\Tests; |
4 | 4 |
|
5 | | -class EventHandlerTest extends \Orchestra\Testbench\TestCase |
| 5 | +use ReflectionClass; |
| 6 | +use Sentry\Laravel\EventHandler; |
| 7 | +use Orchestra\Testbench\TestCase; |
| 8 | + |
| 9 | +class EventHandlerTest extends TestCase |
6 | 10 | { |
7 | 11 | /** |
8 | 12 | * @expectedException \RuntimeException |
9 | 13 | */ |
10 | 14 | public function test_missing_event_handler_throws_exception() |
11 | 15 | { |
12 | | - $handler = new \Sentry\Laravel\EventHandler($this->app->events, []); |
| 16 | + $handler = new EventHandler($this->app->events, []); |
13 | 17 |
|
14 | 18 | $handler->thisIsNotAHandlerAndShouldThrowAnException(); |
15 | 19 | } |
| 20 | + |
| 21 | + public function test_all_mapped_event_handlers_exist() |
| 22 | + { |
| 23 | + $this->tryAllEventHandlerMethods( |
| 24 | + $this->getStaticPropertyValueFromClass(EventHandler::class, 'eventHandlerMap') |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + public function test_all_mapped_auth_event_handlers_exist() |
| 29 | + { |
| 30 | + $this->tryAllEventHandlerMethods( |
| 31 | + $this->getStaticPropertyValueFromClass(EventHandler::class, 'authEventHandlerMap') |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + public function test_all_mapped_queue_event_handlers_exist() |
| 36 | + { |
| 37 | + $this->tryAllEventHandlerMethods( |
| 38 | + $this->getStaticPropertyValueFromClass(EventHandler::class, 'queueEventHandlerMap') |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + private function tryAllEventHandlerMethods(array $methods): void |
| 43 | + { |
| 44 | + $handler = new EventHandler($this->app->events, []); |
| 45 | + |
| 46 | + $methods = array_map(static function ($method) { |
| 47 | + return "{$method}Handler"; |
| 48 | + }, array_unique(array_values($methods))); |
| 49 | + |
| 50 | + foreach ($methods as $handlerMethod) { |
| 51 | + $this->assertTrue(method_exists($handler, $handlerMethod)); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private function getStaticPropertyValueFromClass($className, $attributeName) |
| 56 | + { |
| 57 | + $class = new ReflectionClass($className); |
| 58 | + |
| 59 | + $attributes = $class->getStaticProperties(); |
| 60 | + |
| 61 | + return $attributes[$attributeName]; |
| 62 | + } |
16 | 63 | } |
0 commit comments