Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjunges committed Nov 18, 2024
1 parent 024445d commit 75d8918
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/TrackedJobUsingUuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function test_it_stores_jobs_using_uuid(): void

$job = TrackedJob::first();

$this->assertEquals(TrackedJobStatus::FINISHED, $job->status);
$this->assertEquals(TrackedJobStatus::Finished, $job->status);

$this->assertEquals('1h', $job->duration);
}
Expand Down
38 changes: 28 additions & 10 deletions tests/Traits/TrackableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TrackableTraitTest extends TestCase
{
use RefreshDatabase;

public function getEnvironmentSetUp($app)
public function getEnvironmentSetUp($app): void
{
parent::getEnvironmentSetUp($app);

Expand All @@ -34,11 +34,11 @@ public function test_job_executes_without_fail(): void
$this->assertCount(1, TrackedJob::all());

// This is updated by listening to the JobQueued event.
$this->assertSame(TrackedJobStatus::QUEUED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Queued, TrackedJob::first()->status);

$this->artisan('queue:work --once')->assertExitCode(0);

$this->assertSame(TrackedJobStatus::FINISHED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Finished, TrackedJob::first()->status);

Event::assertNotDispatched(JobFailed::class);
}
Expand All @@ -51,26 +51,44 @@ public function test_it_tracks_failed_jobs(): void

$this->assertCount(1, TrackedJob::all());

$this->assertSame(TrackedJobStatus::QUEUED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Queued, TrackedJob::first()->status);

$this->artisan('queue:work --once')->assertExitCode(0);

$this->assertSame(TrackedJobStatus::FAILED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Failed, TrackedJob::first()->status);
}

public function test_it_can_get_the_job_output(): void
{
$output = ['message' => 'This is a test job', 'exit_code' => 1];
$job = new TestJob($output);

app(Dispatcher::class)->dispatch($job);

$this->assertCount(1, TrackedJob::all());

$this->assertSame(TrackedJobStatus::Queued, TrackedJob::first()->status);

$this->artisan('queue:work --once')->assertExitCode(0);

$this->assertSame(TrackedJobStatus::Finished, TrackedJob::first()->status);

$this->assertSame($output, TrackedJob::first()->output);
}

public function it_can_store_strings_as_the_job_output(): void
{
$job = new TestJob();

app(Dispatcher::class)->dispatch($job);

$this->assertCount(1, TrackedJob::all());

$this->assertSame(TrackedJobStatus::QUEUED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Queued, TrackedJob::first()->status);

$this->artisan('queue:work --once')->assertExitCode(0);

$this->assertSame(TrackedJobStatus::FINISHED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Finished, TrackedJob::first()->status);

$this->assertSame('This is a test job', TrackedJob::first()->output);
}
Expand All @@ -83,11 +101,11 @@ public function test_it_can_get_the_output_for_failed_jobs(): void

$this->assertCount(1, TrackedJob::all());

$this->assertSame(TrackedJobStatus::QUEUED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Queued, TrackedJob::first()->status);

$this->artisan('queue:work --once')->assertExitCode(0);

$this->assertSame(TrackedJobStatus::FAILED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Failed, TrackedJob::first()->status);

$this->assertSame('This job failed.', TrackedJob::first()->output);
}
Expand All @@ -108,6 +126,6 @@ public function test_status_queued_is_updated()

app(Dispatcher::class)->dispatch($job);

$this->assertSame(TrackedJobStatus::QUEUED, TrackedJob::first()->status);
$this->assertSame(TrackedJobStatus::Queued, TrackedJob::first()->status);
}
}

0 comments on commit 75d8918

Please sign in to comment.