-
Notifications
You must be signed in to change notification settings - Fork 340
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
2 changed files
with
129 additions
and
2 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
74 changes: 74 additions & 0 deletions
74
src/module-elasticsuite-core/Test/Unit/Search/Request/Aggregation/PipelineFactoryTest.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,74 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
* @author Richard BAYET <richard.bayet@smile.fr> | ||
* @copyright 2019 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteCore\Test\Unit\Search\Request\Aggregation; | ||
|
||
use Smile\ElasticsuiteCore\Search\Request\Aggregation\PipelineFactory; | ||
use Smile\ElasticsuiteCore\Search\Request\PipelineInterface; | ||
|
||
/** | ||
* Search request pipeline aggregation builder test case. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
* @author Richard BAYET <richard.bayet@smile.fr> | ||
*/ | ||
class PipelineFactoryTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Test the pipeline aggregation creation using the factory. | ||
* | ||
* @return void | ||
*/ | ||
public function testPipelineCreate() | ||
{ | ||
$pipeline = $this->getPipelineFactory()->create('pipelineType', []); | ||
$this->assertInstanceOf(PipelineInterface::class, $pipeline); | ||
} | ||
|
||
/** | ||
* Test trying to create an invalid pipeline aggregation type throws an exception. | ||
* | ||
* @expectedException \LogicException | ||
* @expectedExceptionMessage No factory found for pipeline aggregation of type invalidPipelineType | ||
* | ||
* @return void | ||
*/ | ||
public function testInvalidPipelineCreate() | ||
{ | ||
$this->getPipelineFactory()->create('invalidPipelineType', []); | ||
} | ||
|
||
/** | ||
* Prepared a mocked pipeline aggregation factory. | ||
* | ||
* @return \Smile\ElasticsuiteCore\Search\Request\Aggregation\PipelineFactory | ||
*/ | ||
private function getPipelineFactory() | ||
{ | ||
$pipelineMock = $this->getMockBuilder(PipelineInterface::class)->getMock(); | ||
|
||
$factoryName = sprintf("%s%s", PipelineInterface::class, 'Factory'); | ||
$pipelineFactoryMock = $this->getMockBuilder($factoryName) | ||
->setMethods(['create']) | ||
->getMock(); | ||
|
||
$pipelineFactoryMock->method('create') | ||
->will($this->returnValue($pipelineMock)); | ||
|
||
$factories = ['pipelineType' => $pipelineFactoryMock]; | ||
|
||
return new PipelineFactory($factories); | ||
} | ||
} |