2
2
3
3
namespace Sentry \Features ;
4
4
5
+ use Illuminate \Console \Scheduling \Schedule ;
6
+ use RuntimeException ;
7
+ use Sentry \CheckInStatus ;
5
8
use Sentry \Laravel \Tests \TestCase ;
6
9
use Illuminate \Console \Scheduling \Event ;
7
10
8
11
class ConsoleIntegrationTest extends TestCase
9
12
{
10
- public function setUp (): void
13
+ public function testScheduleMacro (): void
11
14
{
12
- if (!method_exists (Event::class, 'flushMacros ' )) {
13
- $ this ->markTestSkipped ('Macroable::flushMacros() is not available in this Laravel version. ' );
14
- }
15
+ /** @var Event $scheduledEvent */
16
+ $ scheduledEvent = $ this ->getScheduler ()->call (function () {})->sentryMonitor ('test-monitor ' );
17
+
18
+ $ scheduledEvent ->run ($ this ->app );
19
+
20
+ // We expect a total of 2 events to be sent to Sentry:
21
+ // 1. The start check-in event
22
+ // 2. The finish check-in event
23
+ $ this ->assertEquals (2 , $ this ->getEventsCount ());
24
+
25
+ $ finishCheckInEvent = $ this ->getLastEvent ();
26
+
27
+ $ this ->assertNotNull ($ finishCheckInEvent ->getCheckIn ());
28
+ $ this ->assertEquals ('test-monitor ' , $ finishCheckInEvent ->getCheckIn ()->getMonitorSlug ());
29
+ $ this ->assertEquals (CheckInStatus::ok (), $ finishCheckInEvent ->getCheckIn ()->getStatus ());
30
+ }
31
+
32
+ public function testScheduleMacroAutomaticSlug (): void
33
+ {
34
+ /** @var Event $scheduledEvent */
35
+ $ scheduledEvent = $ this ->getScheduler ()->command ('inspire ' )->sentryMonitor ();
15
36
16
- parent ::setUp (); // TODO: Change the autogenerated stub
37
+ $ scheduledEvent ->run ($ this ->app );
38
+
39
+ // We expect a total of 2 events to be sent to Sentry:
40
+ // 1. The start check-in event
41
+ // 2. The finish check-in event
42
+ $ this ->assertEquals (2 , $ this ->getEventsCount ());
43
+
44
+ $ finishCheckInEvent = $ this ->getLastEvent ();
45
+
46
+ $ this ->assertNotNull ($ finishCheckInEvent ->getCheckIn ());
47
+ $ this ->assertEquals ('scheduled_artisan-inspire ' , $ finishCheckInEvent ->getCheckIn ()->getMonitorSlug ());
48
+ }
49
+
50
+ public function testScheduleMacroWithoutSlugOrCommandName (): void
51
+ {
52
+ $ this ->expectException (RuntimeException::class);
53
+
54
+ $ this ->getScheduler ()->call (function () {})->sentryMonitor ();
17
55
}
18
56
19
- public function testArtisanCommandIsRegistered (): void
57
+ public function testScheduleMacroWithoutDsnSet (): void
20
58
{
59
+ $ this ->resetApplicationWithConfig ([
60
+ 'sentry.dsn ' => null ,
61
+ ]);
62
+
63
+ /** @var Event $scheduledEvent */
64
+ $ scheduledEvent = $ this ->getScheduler ()->call ('inspire ' )->sentryMonitor ('test-monitor ' );
65
+
66
+ $ scheduledEvent ->callBeforeCallbacks ($ this ->app );
67
+
68
+ $ this ->assertEquals (0 , $ this ->getEventsCount ());
69
+
70
+ $ scheduledEvent ->finish ($ this ->app , 0 );
71
+
72
+ $ this ->assertEquals (0 , $ this ->getEventsCount ());
73
+ }
74
+
75
+ public function testScheduleMacroIsRegistered (): void
76
+ {
77
+ if (!method_exists (Event::class, 'flushMacros ' )) {
78
+ $ this ->markTestSkipped ('Macroable::flushMacros() is not available in this Laravel version. ' );
79
+ }
80
+
21
81
Event::flushMacros ();
22
82
23
83
$ this ->refreshApplication ();
24
84
25
85
$ this ->assertTrue (Event::hasMacro ('sentryMonitor ' ));
26
86
}
27
87
28
- public function testArtisanCommandIsRegisteredWithoutDsnSet (): void
88
+ public function testScheduleMacroIsRegisteredWithoutDsnSet (): void
29
89
{
90
+ if (!method_exists (Event::class, 'flushMacros ' )) {
91
+ $ this ->markTestSkipped ('Macroable::flushMacros() is not available in this Laravel version. ' );
92
+ }
93
+
30
94
Event::flushMacros ();
31
95
32
96
$ this ->resetApplicationWithConfig ([
@@ -35,4 +99,9 @@ public function testArtisanCommandIsRegisteredWithoutDsnSet(): void
35
99
36
100
$ this ->assertTrue (Event::hasMacro ('sentryMonitor ' ));
37
101
}
102
+
103
+ private function getScheduler (): Schedule
104
+ {
105
+ return $ this ->app ->make (Schedule::class);
106
+ }
38
107
}
0 commit comments