Skip to content

Commit

Permalink
Fix retry
Browse files Browse the repository at this point in the history
  • Loading branch information
TitasGailius committed Mar 30, 2020
1 parent 6a300c6 commit c2b5f27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace TitasGailius\Terminal;

use DateTime;
use Exception;
use DateInterval;
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -200,7 +200,7 @@ public function inBackground()
* @param int $sleep
* @return $this
*/
public function retries(int $times, int $sleep)
public function retries(int $times, int $sleep = 0)
{
$this->retries = [$times, $sleep];

Expand Down
17 changes: 17 additions & 0 deletions tests/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ public function testBuilderProxy()
$this->assertEquals(123, $builder->getPid());
}

/**
* Test that it retries a failed command.
*
* @return void
*/
public function testRetry()
{
$builder = $this->builderWithMockedProccess(function ($mock) {
$mock->shouldReceive('isSuccessful')
->times(3)
->andReturn(false, false , true);
});

$builder->retries(3)
->execute('echo Hello, World');
}

/**
* Create a new builder instance with a mocked process instance.
*
Expand Down

0 comments on commit c2b5f27

Please sign in to comment.