99
1010final class RetryTest extends TestCase
1111{
12- public function testWithoutFailing ()
12+ /**
13+ * Tests that when an operation is successful, its result is returned without retrying.
14+ */
15+ public function testWithoutFailing (): void
1316 {
1417 $ invocations = 0 ;
1518
@@ -23,7 +26,10 @@ public function testWithoutFailing()
2326 self ::assertSame (5 , $ value );
2427 }
2528
26- public function testFailingOnce ()
29+ /**
30+ * Tests that when an operation fails once, it is retried.
31+ */
32+ public function testFailingOnce (): void
2733 {
2834 $ invocations = 0 ;
2935 $ failed = false ;
@@ -45,7 +51,10 @@ public function testFailingOnce()
4551 self ::assertSame (5 , $ value );
4652 }
4753
48- public function testZeroTries ()
54+ /**
55+ * Tests that when an operation is attempted zero times, the operation is not invoked and returns null.
56+ */
57+ public function testZeroTries (): void
4958 {
5059 $ invocations = 0 ;
5160
@@ -59,7 +68,10 @@ public function testZeroTries()
5968 self ::assertNull ($ value );
6069 }
6170
62- public function testFailingTooHard ()
71+ /**
72+ * Tests that when an operation is retried the maximum number of tries, FailingTooHardException is thrown.
73+ */
74+ public function testFailingTooHard (): void
6375 {
6476 $ invocations = 0 ;
6577 $ outerException = $ innerException = null ;
@@ -79,10 +91,10 @@ public function testFailingTooHard()
7991 }
8092
8193 /**
82- * Tests that an error callback receives the exception thrown by the operation, the current attempt and maximum
83- * number of attempts.
94+ * Tests that when an exception is thrown by the operation, the error callback receives that exception, the current
95+ * attempt index and maximum number of attempts.
8496 */
85- public function testErrorCallback ()
97+ public function testErrorCallback (): void
8698 {
8799 $ invocations = $ errors = 0 ;
88100 $ outerException = $ innerException = null ;
@@ -108,20 +120,28 @@ public function testErrorCallback()
108120 }
109121
110122 /**
111- * Tests that an error handler that returns false aborts retrying .
123+ * Tests that when an error handler returns false, retries are aborted .
112124 */
113- public function testErrorCallbackHalt ()
125+ public function testErrorCallbackHalt (): void
114126 {
115127 $ invocations = 0 ;
116128
117- retry ($ tries = 2 , static function () use (&$ invocations ) {
129+ retry (2 , static function () use (&$ invocations ) {
118130 ++$ invocations ;
119131
120132 throw new \RuntimeException ;
121- }, static function () {
122- return false ;
123- });
133+ }, fn () => false );
124134
125135 self ::assertSame (1 , $ invocations );
126136 }
137+
138+ /**
139+ * Tests that when an exception handler throws an exception, the exception is not caught.
140+ */
141+ public function testErrorCallbackCanThrow (): void
142+ {
143+ $ this ->expectExceptionObject ($ exception = new \LogicException );
144+
145+ retry (2 , fn () => throw new \RuntimeException , fn () => throw $ exception );
146+ }
127147}
0 commit comments