Skip to content

Commit

Permalink
throw exception when key is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsupplee committed Oct 17, 2016
1 parent 33bbfa9 commit 591a32c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ private function getConnectionType(array $config)
'composer require google/proto-client-php'
);
}

return $transport;
}

return $transport;
Expand Down
14 changes: 10 additions & 4 deletions src/GrpcTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ public function send(callable $request, array $args)
/**
* Pluck a value out of an array.
*
* @param string $name
* @param string $key
* @param array $args
* @return string
*/
public function pluck($name, array &$args)
public function pluck($key, array &$args)
{
$value = $args[$name];
unset($args[$name]);
if (!isset($args[$key])) {
throw new \InvalidArgumentException(
"Key $key does not exist in the provided array."
);
}

$value = $args[$key];
unset($args[$key]);
return $value;
}
}
9 changes: 9 additions & 0 deletions tests/GrpcTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ public function testPluck()
$this->assertEquals($value, $actualValue);
$this->assertEquals([], $array);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testPluckThrowsExceptionWithInvalidKey()
{
$array = [];
$actualValue = $this->implementation->pluck('not_here', $array);
}
}

0 comments on commit 591a32c

Please sign in to comment.