diff --git a/app/Bus/Events/Beacon/BeaconEventInterface.php b/app/Bus/Events/Beacon/BeaconEventInterface.php new file mode 100644 index 00000000..672fde7d --- /dev/null +++ b/app/Bus/Events/Beacon/BeaconEventInterface.php @@ -0,0 +1,24 @@ + + */ +interface BeaconEventInterface extends EventInterface +{ + // +} diff --git a/app/Bus/Events/Beacon/BeaconFailedToSendEvent.php b/app/Bus/Events/Beacon/BeaconFailedToSendEvent.php new file mode 100644 index 00000000..53ed3eef --- /dev/null +++ b/app/Bus/Events/Beacon/BeaconFailedToSendEvent.php @@ -0,0 +1,22 @@ + + */ +final class BeaconFailedToSendEvent implements BeaconEventInterface +{ + // +} diff --git a/app/Bus/Events/Beacon/BeaconWasSentEvent.php b/app/Bus/Events/Beacon/BeaconWasSentEvent.php new file mode 100644 index 00000000..1d485328 --- /dev/null +++ b/app/Bus/Events/Beacon/BeaconWasSentEvent.php @@ -0,0 +1,22 @@ + + */ +final class BeaconWasSentEvent implements BeaconEventInterface +{ + // +} diff --git a/app/Foundation/Providers/EventServiceProvider.php b/app/Foundation/Providers/EventServiceProvider.php index 9b15570f..bd0784b7 100644 --- a/app/Foundation/Providers/EventServiceProvider.php +++ b/app/Foundation/Providers/EventServiceProvider.php @@ -21,6 +21,12 @@ class EventServiceProvider extends ServiceProvider * @var array */ protected $listen = [ + 'CachetHQ\Cachet\Bus\Events\Beacon\BeaconFailedToSendEvent' => [ + // + ], + 'CachetHQ\Cachet\Bus\Events\Beacon\BeaconWasSentEvent' => [ + // + ], 'CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasAddedEvent' => [ // ], diff --git a/app/Integrations/Core/Beacon.php b/app/Integrations/Core/Beacon.php index 4ce40696..a3763eb8 100644 --- a/app/Integrations/Core/Beacon.php +++ b/app/Integrations/Core/Beacon.php @@ -17,6 +17,8 @@ use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\User; use CachetHQ\Cachet\Settings\Repository as Setting; +use CachetHQ\Cachet\Bus\Events\Beacon\BeaconWasSentEvent; +use CachetHQ\Cachet\Bus\Events\Beacon\BeaconFailedToSendEvent; use Exception; use GuzzleHttp\Client; use Illuminate\Contracts\Config\Repository; @@ -110,6 +112,11 @@ class Beacon implements BeaconContract ]); } catch (Exception $e) { // TODO: Log a warning that the beacon could not be sent. + event(new BeaconFailedToSendEvent()); + + return; } + + event(new BeaconWasSentEvent()); } } diff --git a/tests/Bus/Events/Beacon/AbstractBeaconEventTestCase.php b/tests/Bus/Events/Beacon/AbstractBeaconEventTestCase.php new file mode 100644 index 00000000..7baeb070 --- /dev/null +++ b/tests/Bus/Events/Beacon/AbstractBeaconEventTestCase.php @@ -0,0 +1,31 @@ + + */ +abstract class AbstractBeaconEventTestCase extends AbstractTestCase +{ + use EventTrait; + + protected function getEventInterfaces() + { + return [BeaconEventInterface::class]; + } +} diff --git a/tests/Bus/Events/Beacon/BeaconFailedToSendEventTest.php b/tests/Bus/Events/Beacon/BeaconFailedToSendEventTest.php new file mode 100644 index 00000000..5c785ef2 --- /dev/null +++ b/tests/Bus/Events/Beacon/BeaconFailedToSendEventTest.php @@ -0,0 +1,35 @@ + + */ +class BeaconFailedToSendEventTest extends AbstractBeaconEventTestCase +{ + protected function objectHasHandlers() + { + return false; + } + + protected function getObjectAndParams() + { + $params = []; + $object = new BeaconFailedToSendEvent(); + + return compact('params', 'object'); + } +} diff --git a/tests/Bus/Events/Beacon/BeaconWasSentEventTest.php b/tests/Bus/Events/Beacon/BeaconWasSentEventTest.php new file mode 100644 index 00000000..dea51970 --- /dev/null +++ b/tests/Bus/Events/Beacon/BeaconWasSentEventTest.php @@ -0,0 +1,35 @@ + + */ +class BeaconWasSentEventTest extends AbstractBeaconEventTestCase +{ + protected function objectHasHandlers() + { + return false; + } + + protected function getObjectAndParams() + { + $params = []; + $object = new BeaconWasSentEvent(); + + return compact('params', 'object'); + } +}