Skip to content

Commit

Permalink
Refactoring: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Lorke committed Oct 28, 2018
1 parent 0744db2 commit 9b717a2
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 297 deletions.
130 changes: 130 additions & 0 deletions tests/helpers/CreateMigrationStep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
namespace Tests\Helpers;

use Triadev\EsMigration\Business\Mapper\MigrationTypes;
use Triadev\EsMigration\Contract\ElasticsearchMigrationContract;

class CreateMigrationStep extends \PHPUnit\Framework\TestCase
{
/** @var ElasticsearchMigrationContract */
private $migrationService;

/**
* CreateMigrationStep constructor.
* @param null|string $name
* @param array $data
* @param string $dataName
*/
public function __construct(?string $name = null, array $data = [], string $dataName = '')
{
parent::__construct($name, $data, $dataName);

$this->migrationService = app(ElasticsearchMigrationContract::class);
}

public function createIndex(int $priority = 1)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_CREATE_INDEX,
[
'index' => 'index',
'body' => [
'mappings' => [
'phpunit' => [
'dynamic' => 'strict',
'properties' => [
'title' => [
'type' => 'text'
],
'count' => [
'type' => 'integer'
]
]
]
],
'settings' => [
'refresh_interval' => "30s"
]
]
],
$priority
));
}

public function updateIndex(int $priority = 1, bool $stopOnFailure = true)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_UPDATE_INDEX_MAPPING,
[
'index' => 'index'
],
$priority,
$stopOnFailure
));
}

public function deleteIndex(int $priority = 1)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_DELETE_INDEX,
[
'index' => 'index'
],
$priority
));
}

public function alias(int $priority = 1)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_PUT_ALIAS,
[
'index' => 'index'
],
$priority
));
}

public function deleteByQuery(int $priority = 1)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_DELETE_BY_QUERY,
[
'index' => 'index',
'query' => []
],
$priority
));
}

public function updateByQuery(int $priority = 1)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_UPDATE_BY_QUERY,
[
'index' => 'index',
'query' => []
],
$priority
));
}

public function reindex(int $priority = 1)
{
$this->assertTrue($this->migrationService->addMigrationStep(
'phpunit',
MigrationTypes::MIGRATION_TYPE_REINDEX,
[
'index' => 'index',
'destindex' => 'phpunit'
],
$priority
));
}
}
Loading

0 comments on commit 9b717a2

Please sign in to comment.