-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
...xpander/Plugin/Elasticsearch/QueryExpander/ModelKeyAndStyleKeyQueryExpanderPluginTest.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,113 @@ | ||
<?php | ||
|
||
namespace FondOfSpryker\Client\ProductPageSearchExpander\Plugin\Elasticsearch\QueryExpander; | ||
|
||
use Codeception\Test\Unit; | ||
use Elastica\Query; | ||
use Elastica\Query\BoolQuery; | ||
use Elastica\Query\Match as MatchQuery; | ||
use FondOfSpryker\Client\ProductPageSearchExpander\ProductPageSearchExpanderFactory; | ||
use Spryker\Client\Search\Model\Elasticsearch\Query\QueryBuilder; | ||
use Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface; | ||
use FondOfSpryker\Shared\ProductPageSearchExpander\ProductPageSearchExpanderConstants; | ||
|
||
class ModelKeyAndStyleKeyQueryExpanderPluginTest extends Unit | ||
{ | ||
/** | ||
* @var \Spryker\Client\Search\Model\Elasticsearch\Query\QueryBuilder|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $queryBuilderMock; | ||
|
||
/** | ||
* @var \FondOfSpryker\Client\ProductPageSearchExpander\Plugin\Elasticsearch\QueryExpander\ModelKeyAndStyleKeyQueryExpanderPlugin | ||
*/ | ||
protected $queryExpanderPlugin; | ||
|
||
/** | ||
* @var \FondOfSpryker\Client\ProductPageSearchExpander\ProductPageSearchExpanderFactory|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $factoryMock; | ||
|
||
/** | ||
* @var \Elastica\Query|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $elasticaQueryMock; | ||
|
||
/** | ||
* @var \Spryker\Client\SearchExtension\Dependency\Plugin\QueryInterface|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $searchQueryMock; | ||
|
||
/** | ||
* @var \Elastica\Query\Match|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $matchQueryMock; | ||
|
||
/** | ||
* @var \Elastica\Query\BoolQuery|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $boolQueryMock; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function _before() | ||
{ | ||
parent::_before(); // TODO: Change the autogenerated stub | ||
|
||
$this->factoryMock = $this->getMockBuilder(ProductPageSearchExpanderFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->searchQueryMock = $this->getMockBuilder(QueryInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->elasticaQueryMock = $this->getMockBuilder(Query::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->boolQueryMock = $this->getMockBuilder(BoolQuery::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->matchQueryMock = $this->getMockBuilder(MatchQuery::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->queryBuilderMock = $this->getMockBuilder(QueryBuilder::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->queryExpanderPlugin = new ModelKeyAndStyleKeyQueryExpanderPlugin(); | ||
$this->queryExpanderPlugin->setFactory($this->factoryMock); | ||
} | ||
|
||
public function testExpandQuerySuccess() | ||
{ | ||
$this->searchQueryMock->expects($this->exactly(2)) | ||
->method('getSearchQuery') | ||
->willReturn($this->elasticaQueryMock); | ||
|
||
$this->factoryMock->expects($this->exactly(2)) | ||
->method('createQueryBuilder') | ||
->willReturn($this->queryBuilderMock); | ||
|
||
$this->elasticaQueryMock->expects($this->once()) | ||
->method('getQuery') | ||
->willReturn($this->boolQueryMock); | ||
|
||
$this->queryBuilderMock->expects($this->exactly(2)) | ||
->method('createMatchQuery') | ||
->willReturn($this->matchQueryMock); | ||
|
||
$this->matchQueryMock->expects($this->exactly(2)) | ||
->method('setField') | ||
->willReturn($this->matchQueryMock); | ||
|
||
$this->queryExpanderPlugin->expandQuery($this->searchQueryMock, [ | ||
ProductPageSearchExpanderConstants::MODEL_KEY => 'model_key', | ||
ProductPageSearchExpanderConstants::STYLE_KEY => 'style_key', | ||
]); | ||
} | ||
} |