Skip to content

Commit 70329b1

Browse files
committed
Add tests
1 parent e31457b commit 70329b1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

test/Sentry/Features/ConsoleSchedulingIntegrationTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use DateTimeZone;
66
use Illuminate\Console\Scheduling\Schedule;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Foundation\Queue\Queueable;
79
use RuntimeException;
810
use Sentry\Laravel\Tests\TestCase;
911
use Illuminate\Console\Scheduling\Event;
@@ -121,8 +123,59 @@ public function testScheduleMacroIsRegisteredWithoutDsnSet(): void
121123
$this->assertTrue(Event::hasMacro('sentryMonitor'));
122124
}
123125

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+
124168
private function getScheduler(): Schedule
125169
{
126170
return $this->app->make(Schedule::class);
127171
}
128172
}
173+
174+
class ScheduledQueuedJob implements ShouldQueue
175+
{
176+
use Queueable;
177+
178+
public function handle(): void
179+
{
180+
}
181+
}

0 commit comments

Comments
 (0)