Skip to content

[12.x] Add some tests coverage for Queue Exception handling #55442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/Queue/QueueExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,50 @@ public function test_it_can_create_max_attempts_exception_for_job()
$this->assertSame('App\\Jobs\\UnderlyingJob has been attempted too many times.', $e->getMessage());
$this->assertSame($job, $e->job);
}

public function test_timeout_exception_can_be_converted_to_string()
{
$e = TimeoutExceededException::forJob($job = new MyFakeRedisJob());

$this->assertIsString((string) $e);
$this->assertStringContainsString('timed out', (string) $e);
}

public function test_max_attempts_exception_can_be_converted_to_string()
{
$e = MaxAttemptsExceededException::forJob($job = new MyFakeRedisJob());

$this->assertIsString((string) $e);
$this->assertStringContainsString('attempted too many times', (string) $e);
}

public function test_exceptions_preserve_job_instance()
{
$job = new MyFakeRedisJob();

$timeoutException = TimeoutExceededException::forJob($job);
$maxAttemptsException = MaxAttemptsExceededException::forJob($job);

$this->assertSame($job, $timeoutException->job);
$this->assertSame($job, $maxAttemptsException->job);
$this->assertInstanceOf(RedisJob::class, $timeoutException->job);
$this->assertInstanceOf(RedisJob::class, $maxAttemptsException->job);
}

public function test_custom_job_name_resolution()
{
$job = new class extends MyFakeRedisJob
{
public function resolveName()
{
return 'Custom\\Job\\Name';
}
};

$e = TimeoutExceededException::forJob($job);

$this->assertStringContainsString('Custom\\Job\\Name', $e->getMessage());
}
}

class MyFakeRedisJob extends RedisJob
Expand Down