From d80a9d3d1fc0df6654298cf25c4b45719224d819 Mon Sep 17 00:00:00 2001
From: Roshandelpoor Mohammad <roshandelpoor@outlook.com>
Date: Wed, 16 Apr 2025 22:11:48 +0330
Subject: [PATCH] Add some tests for Queue Exception handling

---
 tests/Queue/QueueExceptionTest.php | 44 ++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/tests/Queue/QueueExceptionTest.php b/tests/Queue/QueueExceptionTest.php
index 9b4b246b47cd..2c352783dae7 100644
--- a/tests/Queue/QueueExceptionTest.php
+++ b/tests/Queue/QueueExceptionTest.php
@@ -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