Skip to content

Commit

Permalink
setOptions must honor the type of option param, close #11
Browse files Browse the repository at this point in the history
  • Loading branch information
yriveiro committed Apr 25, 2018
1 parent 1682501 commit 166cd27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
6 changes: 1 addition & 5 deletions src/Backoff.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ public static function getDefaultOptions() : array
*
* @return BackoffInterface
*/
public function setOptions($options) : BackoffInterface
public function setOptions(array $options) : BackoffInterface
{
if (!is_array($options)) {
$options = [$options];
}

$this->options = array_merge($this->options, $options);

return $this;
Expand Down
22 changes: 8 additions & 14 deletions tests/BackoffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,16 @@ public function testSetOptions()
$this->assertEquals($expected, $options->getValue($this->backoff));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testSetOptionsNotAnArray()
{
$options = 10;

$this->backoff->setOptions($options);

$options = new ReflectionProperty($this->backoff, 'options');
$options->setAccessible(true);

$expected = array(
0 => 10,
'cap' => 1000000,
'maxAttempts' => 0
);

$this->assertEquals($expected, $options->getValue($this->backoff));
try {
$this->backoff->setOptions(10);
} catch (TypeError $e) {
throw new InvalidArgumentException();
}
}

/**
Expand Down

0 comments on commit 166cd27

Please sign in to comment.