22
33namespace Sentry \Features ;
44
5+ use DateTimeZone ;
56use Illuminate \Console \Scheduling \Schedule ;
67use RuntimeException ;
78use Sentry \Laravel \Tests \TestCase ;
@@ -27,6 +28,34 @@ public function testScheduleMacro(): void
2728 $ this ->assertEquals ('test-monitor ' , $ finishCheckInEvent ->getCheckIn ()->getMonitorSlug ());
2829 }
2930
31+ /**
32+ * When a timezone was defined on a command this would fail with:
33+ * Sentry\MonitorConfig::__construct(): Argument #4 ($timezone) must be of type ?string, DateTimeZone given
34+ * This test ensures that the timezone is properly converted to a string as expected.
35+ */
36+ public function testScheduleMacroWithTimeZone (): void
37+ {
38+ $ expectedTimezone = 'UTC ' ;
39+
40+ /** @var Event $scheduledEvent */
41+ $ scheduledEvent = $ this ->getScheduler ()
42+ ->call (function () {})
43+ ->timezone (new DateTimeZone ($ expectedTimezone ))
44+ ->sentryMonitor ('test-timezone-monitor ' );
45+
46+ $ scheduledEvent ->run ($ this ->app );
47+
48+ // We expect a total of 2 events to be sent to Sentry:
49+ // 1. The start check-in event
50+ // 2. The finish check-in event
51+ $ this ->assertEquals (2 , $ this ->getEventsCount ());
52+
53+ $ finishCheckInEvent = $ this ->getLastEvent ();
54+
55+ $ this ->assertNotNull ($ finishCheckInEvent ->getCheckIn ());
56+ $ this ->assertEquals ($ expectedTimezone , $ finishCheckInEvent ->getCheckIn ()->getMonitorConfig ()->getTimezone ());
57+ }
58+
3059 public function testScheduleMacroAutomaticSlug (): void
3160 {
3261 /** @var Event $scheduledEvent */
0 commit comments