Skip to content

Commit c2b5f27

Browse files
committed
Fix retry
1 parent 6a300c6 commit c2b5f27

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace TitasGailius\Terminal;
44

55
use DateTime;
6+
use Exception;
67
use DateInterval;
78
use BadMethodCallException;
8-
use Exception;
99
use InvalidArgumentException;
1010
use Symfony\Component\Process\Process;
1111

@@ -200,7 +200,7 @@ public function inBackground()
200200
* @param int $sleep
201201
* @return $this
202202
*/
203-
public function retries(int $times, int $sleep)
203+
public function retries(int $times, int $sleep = 0)
204204
{
205205
$this->retries = [$times, $sleep];
206206

tests/BuilderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,23 @@ public function testBuilderProxy()
242242
$this->assertEquals(123, $builder->getPid());
243243
}
244244

245+
/**
246+
* Test that it retries a failed command.
247+
*
248+
* @return void
249+
*/
250+
public function testRetry()
251+
{
252+
$builder = $this->builderWithMockedProccess(function ($mock) {
253+
$mock->shouldReceive('isSuccessful')
254+
->times(3)
255+
->andReturn(false, false , true);
256+
});
257+
258+
$builder->retries(3)
259+
->execute('echo Hello, World');
260+
}
261+
245262
/**
246263
* Create a new builder instance with a mocked process instance.
247264
*

0 commit comments

Comments
 (0)