|
4 | 4 |
|
5 | 5 | use DateTimeZone; |
6 | 6 | use Illuminate\Console\Scheduling\Schedule; |
| 7 | +use Illuminate\Contracts\Queue\ShouldQueue; |
| 8 | +use Illuminate\Foundation\Queue\Queueable; |
7 | 9 | use RuntimeException; |
8 | 10 | use Sentry\Laravel\Tests\TestCase; |
9 | 11 | use Illuminate\Console\Scheduling\Event; |
@@ -121,8 +123,59 @@ public function testScheduleMacroIsRegisteredWithoutDsnSet(): void |
121 | 123 | $this->assertTrue(Event::hasMacro('sentryMonitor')); |
122 | 124 | } |
123 | 125 |
|
| 126 | + /** @define-env envSamplingAllTransactions */ |
| 127 | + public function testScheduledCommandCreatesTransaction(): void |
| 128 | + { |
| 129 | + $this->getScheduler()->command('inspire')->everyMinute(); |
| 130 | + |
| 131 | + $this->artisan('schedule:run'); |
| 132 | + |
| 133 | + $this->assertSentryTransactionCount(1); |
| 134 | + |
| 135 | + $transaction = $this->getLastSentryEvent(); |
| 136 | + |
| 137 | + $this->assertEquals('inspire', $transaction->getTransaction()); |
| 138 | + } |
| 139 | + |
| 140 | + /** @define-env envSamplingAllTransactions */ |
| 141 | + public function testScheduledClosureCreatesTransaction(): void |
| 142 | + { |
| 143 | + $this->getScheduler()->call(function () {})->everyMinute(); |
| 144 | + |
| 145 | + $this->artisan('schedule:run'); |
| 146 | + |
| 147 | + $this->assertSentryTransactionCount(1); |
| 148 | + |
| 149 | + $transaction = $this->getLastSentryEvent(); |
| 150 | + |
| 151 | + $this->assertEquals('Closure', $transaction->getTransaction()); |
| 152 | + } |
| 153 | + |
| 154 | + /** @define-env envSamplingAllTransactions */ |
| 155 | + public function testScheduledJobCreatesTransaction(): void |
| 156 | + { |
| 157 | + $this->getScheduler()->job(ScheduledQueuedJob::class)->everyMinute(); |
| 158 | + |
| 159 | + $this->artisan('schedule:run'); |
| 160 | + |
| 161 | + $this->assertSentryTransactionCount(1); |
| 162 | + |
| 163 | + $transaction = $this->getLastSentryEvent(); |
| 164 | + |
| 165 | + $this->assertEquals(ScheduledQueuedJob::class, $transaction->getTransaction()); |
| 166 | + } |
| 167 | + |
124 | 168 | private function getScheduler(): Schedule |
125 | 169 | { |
126 | 170 | return $this->app->make(Schedule::class); |
127 | 171 | } |
128 | 172 | } |
| 173 | + |
| 174 | +class ScheduledQueuedJob implements ShouldQueue |
| 175 | +{ |
| 176 | + use Queueable; |
| 177 | + |
| 178 | + public function handle(): void |
| 179 | + { |
| 180 | + } |
| 181 | +} |
0 commit comments