forked from basemkhirat/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ffab37
commit e4af833
Showing
11 changed files
with
321 additions
and
219 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
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 |
---|---|---|
@@ -1,45 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Matchory\Elasticsearch\Tests; | ||
|
||
use Matchory\Elasticsearch\Tests\Traits\ESQueryTrait; | ||
|
||
use PHPUnit\Framework\ExpectationFailedException; | ||
use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; | ||
use PHPUnit\Framework\MockObject\ClassIsFinalException; | ||
use PHPUnit\Framework\MockObject\DuplicateMethodException; | ||
use PHPUnit\Framework\MockObject\InvalidMethodNameException; | ||
use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; | ||
use PHPUnit\Framework\MockObject\ReflectionException; | ||
use PHPUnit\Framework\MockObject\RuntimeException; | ||
use PHPUnit\Framework\MockObject\UnknownTypeException; | ||
use PHPUnit\Framework\TestCase; | ||
use SebastianBergmann\RecursionContext\InvalidArgumentException; | ||
|
||
class IgnoreTest extends TestCase | ||
{ | ||
|
||
use ESQueryTrait; | ||
|
||
/** | ||
* Test the ignore() method. | ||
* @return void | ||
* @throws ClassAlreadyExistsException | ||
* @throws ClassIsFinalException | ||
* @throws DuplicateMethodException | ||
* @throws ExpectationFailedException | ||
* @throws InvalidArgumentException | ||
* @throws InvalidMethodNameException | ||
* @throws OriginalConstructorInvocationRequiredException | ||
* @throws ReflectionException | ||
* @throws RuntimeException | ||
* @throws UnknownTypeException | ||
* @throws \PHPUnit\Framework\InvalidArgumentException | ||
* @test | ||
*/ | ||
public function testIgnoreMethod(): void | ||
public function ignore(): void | ||
{ | ||
self::assertEquals($this->getExpected(404), $this->getActual(404)); | ||
self::assertEquals($this->getExpected(500, 404), $this->getActual(500, 404)); | ||
self::assertEquals( | ||
$this->getExpected(404), | ||
$this->getActual(404) | ||
); | ||
self::assertEquals( | ||
$this->getExpected(500, 404), | ||
$this->getActual(500, 404) | ||
); | ||
} | ||
|
||
/** | ||
* Get The expected results. | ||
* @param int ...$args | ||
* | ||
* @return array | ||
* @throws ClassAlreadyExistsException | ||
* @throws ClassIsFinalException | ||
* @throws DuplicateMethodException | ||
* @throws InvalidMethodNameException | ||
* @throws OriginalConstructorInvocationRequiredException | ||
* @throws ReflectionException | ||
* @throws RuntimeException | ||
* @throws UnknownTypeException | ||
* @throws \PHPUnit\Framework\InvalidArgumentException | ||
*/ | ||
protected function getExpected() | ||
protected function getActual(int ...$args): array | ||
{ | ||
$query = $this->getQueryArray(); | ||
|
||
$query["client"]["ignore"] = func_get_args(); | ||
|
||
return $query; | ||
return $this->getQueryObject() | ||
->ignore($args) | ||
->toArray(); | ||
} | ||
|
||
/** | ||
* Get The actual results. | ||
* @return mixed | ||
*/ | ||
protected function getActual() | ||
protected function getExpected(int ...$args): array | ||
{ | ||
return $this->getQueryObject()->ignore(func_get_args())->query(); | ||
$query = $this->getQueryArray(); | ||
$query['client']['ignore'] = $args; | ||
|
||
return $query; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,57 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Matchory\Elasticsearch\Tests; | ||
|
||
use Matchory\Elasticsearch\Tests\Traits\ESQueryTrait; | ||
use PHPUnit\Framework\ExpectationFailedException; | ||
use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; | ||
use PHPUnit\Framework\MockObject\ClassIsFinalException; | ||
use PHPUnit\Framework\MockObject\DuplicateMethodException; | ||
use PHPUnit\Framework\MockObject\InvalidMethodNameException; | ||
use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; | ||
use PHPUnit\Framework\MockObject\ReflectionException; | ||
use PHPUnit\Framework\MockObject\RuntimeException; | ||
use PHPUnit\Framework\MockObject\UnknownTypeException; | ||
use PHPUnit\Framework\TestCase; | ||
use SebastianBergmann\RecursionContext\InvalidArgumentException; | ||
|
||
class SelectTest extends TestCase | ||
{ | ||
|
||
use ESQueryTrait; | ||
|
||
/** | ||
* Test the select() method. | ||
* | ||
* @return void | ||
* @throws ClassAlreadyExistsException | ||
* @throws ClassIsFinalException | ||
* @throws DuplicateMethodException | ||
* @throws ExpectationFailedException | ||
* @throws InvalidArgumentException | ||
* @throws InvalidMethodNameException | ||
* @throws OriginalConstructorInvocationRequiredException | ||
* @throws ReflectionException | ||
* @throws RuntimeException | ||
* @throws UnknownTypeException | ||
* @throws \PHPUnit\Framework\InvalidArgumentException | ||
* @test | ||
*/ | ||
public function testIgnoreMethod(): void | ||
public function select(): void | ||
{ | ||
self::assertEquals( | ||
$this->getExpected("title", "content"), | ||
$this->getActual("title", "content") | ||
$this->getExpected('foo', 'bar'), | ||
$this->getActual('foo', 'bar') | ||
); | ||
} | ||
|
||
/** | ||
* Get The expected results. | ||
* @param string ...$fields | ||
* | ||
* @return array | ||
* @throws ClassAlreadyExistsException | ||
* @throws ClassIsFinalException | ||
* @throws DuplicateMethodException | ||
* @throws InvalidMethodNameException | ||
* @throws OriginalConstructorInvocationRequiredException | ||
* @throws ReflectionException | ||
* @throws RuntimeException | ||
* @throws UnknownTypeException | ||
* @throws \PHPUnit\Framework\InvalidArgumentException | ||
*/ | ||
protected function getExpected(): array | ||
protected function getActual(string ...$fields): array | ||
{ | ||
$query = $this->getQueryArray(); | ||
|
||
$query["body"]["_source"]['include'] = func_get_args(); | ||
$query["body"]["_source"]['exclude'] = []; | ||
|
||
return $query; | ||
return $this | ||
->getQueryObject() | ||
->select($fields) | ||
->toArray(); | ||
} | ||
|
||
/** | ||
* Get The actual results. | ||
* @param string ...$fields | ||
* | ||
* @return array | ||
*/ | ||
protected function getActual(): array | ||
protected function getExpected(string ...$fields): array | ||
{ | ||
return $this | ||
->getQueryObject() | ||
->select(func_get_args()) | ||
->query(); | ||
$query = $this->getQueryArray(); | ||
|
||
$query['body']['_source']['includes'] = $fields; | ||
$query['body']['_source']['excludes'] = []; | ||
|
||
return $query; | ||
} | ||
} |
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
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
Oops, something went wrong.