Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and implemented exists functionality for elasticsearch se…
…rvice
- Loading branch information
Showing
4 changed files
with
148 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Spira framework. | ||
* | ||
* @link https://github.com/spira/spira | ||
* | ||
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Class ElasticSearchTest. | ||
*/ | ||
class ElasticSearchTest extends TestCase | ||
{ | ||
public function testCreateIndex() | ||
{ | ||
$elasticSearchMock = Mockery::mock(\Elasticsearch\Client::class)->makePartial(); | ||
$indicesMock = Mockery::mock(\Elasticsearch\Namespaces\IndicesNamespace::class); | ||
|
||
$elasticSearchMock->shouldReceive('indices')->andReturn($indicesMock); | ||
$indicesMock->shouldReceive('create')->with(\Mockery::subset(['index' => config()->get('elasticquent.default_index')])); | ||
|
||
$elasticSearchService = new \App\Services\ElasticSearch($elasticSearchMock); | ||
|
||
$elasticSearchService->createIndex(); | ||
} | ||
|
||
public function testCreateIndexForModel() | ||
{ | ||
$elasticSearchMock = Mockery::mock(\Elasticsearch\Client::class)->makePartial(); | ||
$indicesMock = Mockery::mock(\Elasticsearch\Namespaces\IndicesNamespace::class); | ||
|
||
$elasticSearchMock->shouldReceive('indices')->andReturn($indicesMock); | ||
$indicesMock->shouldReceive('create')->with(\Mockery::subset(['index' => 'foo'])); | ||
|
||
$elasticSearchService = new \App\Services\ElasticSearch($elasticSearchMock); | ||
|
||
$elasticSearchService->createIndex(new class extends \Spira\Core\Model\Model\IndexedModel { | ||
|
||
public function getIndexName() | ||
{ | ||
return 'foo'; | ||
} | ||
|
||
}); | ||
} | ||
|
||
public function testDeleteIndex() | ||
{ | ||
$elasticSearchMock = Mockery::mock(\Elasticsearch\Client::class)->makePartial(); | ||
$indicesMock = Mockery::mock(\Elasticsearch\Namespaces\IndicesNamespace::class); | ||
|
||
$elasticSearchMock->shouldReceive('indices')->andReturn($indicesMock); | ||
$indicesMock->shouldReceive('delete')->with(\Mockery::subset(['index' => config()->get('elasticquent.default_index')])); | ||
|
||
$elasticSearchService = new \App\Services\ElasticSearch($elasticSearchMock); | ||
|
||
$elasticSearchService->deleteIndex(); | ||
} | ||
|
||
public function testDeleteIndexForModel() | ||
{ | ||
$elasticSearchMock = Mockery::mock(\Elasticsearch\Client::class)->makePartial(); | ||
$indicesMock = Mockery::mock(\Elasticsearch\Namespaces\IndicesNamespace::class); | ||
|
||
$elasticSearchMock->shouldReceive('indices')->andReturn($indicesMock); | ||
$indicesMock->shouldReceive('delete')->with(\Mockery::subset(['index' => 'foo'])); | ||
|
||
$elasticSearchService = new \App\Services\ElasticSearch($elasticSearchMock); | ||
|
||
$elasticSearchService->deleteIndex(new class extends \Spira\Core\Model\Model\IndexedModel { | ||
|
||
public function getIndexName() | ||
{ | ||
return 'foo'; | ||
} | ||
|
||
}); | ||
} | ||
|
||
public function testIndexExists() | ||
{ | ||
$elasticSearchMock = Mockery::mock(\Elasticsearch\Client::class)->makePartial(); | ||
$indicesMock = Mockery::mock(\Elasticsearch\Namespaces\IndicesNamespace::class); | ||
|
||
$elasticSearchMock->shouldReceive('indices')->andReturn($indicesMock); | ||
$indicesMock->shouldReceive('exists')->with(\Mockery::subset(['index' => 'foo'])); | ||
|
||
$elasticSearchService = new \App\Services\ElasticSearch($elasticSearchMock); | ||
|
||
$elasticSearchService->indexExists(new class extends \Spira\Core\Model\Model\IndexedModel { | ||
|
||
public function getIndexName() | ||
{ | ||
return 'foo'; | ||
} | ||
|
||
}); | ||
} | ||
|
||
public function testIndexExistsForModel() | ||
{ | ||
$elasticSearchMock = Mockery::mock(\Elasticsearch\Client::class)->makePartial(); | ||
$indicesMock = Mockery::mock(\Elasticsearch\Namespaces\IndicesNamespace::class); | ||
|
||
$elasticSearchMock->shouldReceive('indices')->andReturn($indicesMock); | ||
$indicesMock->shouldReceive('exists')->with(\Mockery::subset(['index' => 'foo'])); | ||
|
||
$elasticSearchService = new \App\Services\ElasticSearch($elasticSearchMock); | ||
|
||
$elasticSearchService->indexExists(new class extends \Spira\Core\Model\Model\IndexedModel { | ||
|
||
public function getIndexName() | ||
{ | ||
return 'foo'; | ||
} | ||
|
||
}); | ||
} | ||
|
||
} |