|
6 | 6 | use GuzzleHttp\Psr7\Response;
|
7 | 7 | use Laravel\Forge\Exceptions\FailedActionException;
|
8 | 8 | use Laravel\Forge\Exceptions\NotFoundException;
|
| 9 | +use Laravel\Forge\Exceptions\TimeoutException; |
9 | 10 | use Laravel\Forge\Exceptions\ValidationException;
|
10 | 11 | use Laravel\Forge\Forge;
|
| 12 | +use Laravel\Forge\MakesHttpRequests; |
11 | 13 | use Mockery;
|
12 | 14 | use PHPUnit\Framework\TestCase;
|
13 | 15 |
|
@@ -87,4 +89,89 @@ public function test_handling_failed_action_errors()
|
87 | 89 | $this->assertSame('Error!', $e->getMessage());
|
88 | 90 | }
|
89 | 91 | }
|
| 92 | + |
| 93 | + public function testRetryHandlesFalseResultFromClosure() |
| 94 | + { |
| 95 | + $requestMaker = new class() |
| 96 | + { |
| 97 | + use MakesHttpRequests; |
| 98 | + }; |
| 99 | + |
| 100 | + try { |
| 101 | + $requestMaker->retry(0, function () { |
| 102 | + return false; |
| 103 | + }, 0); |
| 104 | + $this->fail(); |
| 105 | + } catch (TimeoutException $e) { |
| 106 | + $this->assertSame([], $e->output()); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + public function testRetryHandlesNullResultFromClosure() |
| 111 | + { |
| 112 | + $requestMaker = new class() |
| 113 | + { |
| 114 | + use MakesHttpRequests; |
| 115 | + }; |
| 116 | + |
| 117 | + try { |
| 118 | + $requestMaker->retry(0, function () { |
| 119 | + return null; |
| 120 | + }, 0); |
| 121 | + $this->fail(); |
| 122 | + } catch (TimeoutException $e) { |
| 123 | + $this->assertSame([], $e->output()); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + public function testRetryHandlesFalseyStringResultFromClosure() |
| 128 | + { |
| 129 | + $requestMaker = new class() |
| 130 | + { |
| 131 | + use MakesHttpRequests; |
| 132 | + }; |
| 133 | + |
| 134 | + try { |
| 135 | + $requestMaker->retry(0, function () { |
| 136 | + return ''; |
| 137 | + }, 0); |
| 138 | + $this->fail(); |
| 139 | + } catch (TimeoutException $e) { |
| 140 | + $this->assertSame([''], $e->output()); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + public function testRetryHandlesFalseyNumerResultFromClosure() |
| 145 | + { |
| 146 | + $requestMaker = new class() |
| 147 | + { |
| 148 | + use MakesHttpRequests; |
| 149 | + }; |
| 150 | + |
| 151 | + try { |
| 152 | + $requestMaker->retry(0, function () { |
| 153 | + return 0; |
| 154 | + }, 0); |
| 155 | + $this->fail(); |
| 156 | + } catch (TimeoutException $e) { |
| 157 | + $this->assertSame([0], $e->output()); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + public function testRetryHandlesFalseyArrayResultFromClosure() |
| 162 | + { |
| 163 | + $requestMaker = new class() |
| 164 | + { |
| 165 | + use MakesHttpRequests; |
| 166 | + }; |
| 167 | + |
| 168 | + try { |
| 169 | + $requestMaker->retry(0, function () { |
| 170 | + return []; |
| 171 | + }, 0); |
| 172 | + $this->fail(); |
| 173 | + } catch (TimeoutException $e) { |
| 174 | + $this->assertSame([], $e->output()); |
| 175 | + } |
| 176 | + } |
90 | 177 | }
|
0 commit comments