-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
array_diff
to Check Endpoint Parameters (#514)
Slightly nicer than the old array_search method that iterates through every user provided param. Also gives the user feed back on *all* invalid parameters at once, rather than just one at a time.
- Loading branch information
1 parent
b262dca
commit 46f7f36
Showing
2 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/Elasticsearch/Tests/Endpoints/AbstractEndpointTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Elasticsearch\Tests\Endpoints; | ||
|
||
use Elasticsearch\Endpoints\AbstractEndpoint; | ||
|
||
class AbstractEndpointTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $endpoint; | ||
|
||
public static function invalidParameters() | ||
{ | ||
return [ | ||
[['invalid' => 10]], | ||
[['invalid' => 10, 'invalid2' => 'another']], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider invalidParameters | ||
* @expectedException Elasticsearch\Common\Exceptions\UnexpectedValueException | ||
*/ | ||
public function testInvalidParamsCauseErrorsWhenProvidedToSetParams(array $params) | ||
{ | ||
$this->endpoint->expects($this->once()) | ||
->method('getParamWhitelist') | ||
->willReturn(['one', 'two']); | ||
|
||
$this->endpoint->setParams($params); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$this->endpoint = $this->getMockForAbstractClass(AbstractEndpoint::class); | ||
} | ||
} |