Skip to content

Commit

Permalink
Added integration tests for commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Lorke committed Sep 6, 2018
1 parent 3cf2ae1 commit 502c544
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 15 deletions.
29 changes: 20 additions & 9 deletions tests/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@

class IntegrationTestCase extends TestCase
{
/** @var array */
private $mapping;

/**
* Setup the test environment.
*/
public function setUp()
{
parent::setUp();

$this->mapping = include __DIR__ . '/integration/mapping.php';
}

/**
Expand All @@ -33,7 +28,10 @@ protected function getEnvironmentSetUp($app)
'pass' => '',
'deploy' => [
'version' => [
'indices' => []
'indices' => [
'from' => '0.0.0',
'to' => '1.0.0'
]
]
],
'snapshot' => [
Expand All @@ -43,13 +41,26 @@ protected function getEnvironmentSetUp($app)
],
'config' => [
'retries' => 2,
'indices' => []
'indices' => [
'phpunit' => $this->getMapping()
]
]
]);
}

protected function getMapping() : array
public function getMapping() : array
{
return $this->mapping;
return [
'mappings' => [
'phpunit' => [
'dynamic' => 'strict',
'properties' => [
'title' => [
'type' => 'text'
]
]
]
]
];
}
}
52 changes: 52 additions & 0 deletions tests/integration/Console/Commands/Alias/CreateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace Tests\Integration\Console\Commands\Alias;

use Tests\IntegrationTestCase;
use Triadev\Es\Contract\ElasticsearchAliasContract;
use Triadev\Es\Contract\ElasticsearchIndexContract;

class CreateTest extends IntegrationTestCase
{
/** @var ElasticsearchIndexContract */
private $serviceIndex;

/** @var ElasticsearchAliasContract */
private $serviceAlias;

public function setUp()
{
parent::setUp();

$this->serviceIndex = app(ElasticsearchIndexContract::class);
$this->serviceAlias = app(ElasticsearchAliasContract::class);

$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($this->serviceIndex->existIndex([
'phpunit'
], '1.0.0'));

if ($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0')) {
$this->serviceAlias->deleteAlias('phpunit', 'alias', '1.0.0');
}
}

/**
* @test
*/
public function it_creates_an_alias()
{
$this->assertFalse($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));

$this->artisan('triadev:es:alias:create', [
'index' => 'phpunit',
'alias' => 'alias',
'version' => '1.0.0'
])->assertExitCode(0);

$this->assertTrue($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));
}
}
58 changes: 58 additions & 0 deletions tests/integration/Console/Commands/Alias/DeleteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Tests\Integration\Console\Commands\Alias;

use Tests\IntegrationTestCase;
use Triadev\Es\Contract\ElasticsearchAliasContract;
use Triadev\Es\Contract\ElasticsearchIndexContract;

class DeleteTest extends IntegrationTestCase
{
/** @var ElasticsearchIndexContract */
private $serviceIndex;

/** @var ElasticsearchAliasContract */
private $serviceAlias;

public function setUp()
{
parent::setUp();

$this->serviceIndex = app(ElasticsearchIndexContract::class);
$this->serviceAlias = app(ElasticsearchAliasContract::class);

$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($this->serviceIndex->existIndex([
'phpunit'
], '1.0.0'));

if ($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0')) {
$this->serviceAlias->deleteAlias('phpunit', 'alias', '1.0.0');
}
}

/**
* @test
*/
public function it_creates_an_alias()
{
$this->artisan('triadev:es:alias:create', [
'index' => 'phpunit',
'alias' => 'alias',
'version' => '1.0.0'
])->assertExitCode(0);

$this->assertTrue($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));

$this->artisan('triadev:es:alias:delete', [
'index' => 'phpunit',
'alias' => 'alias',
'version' => '1.0.0'
])->assertExitCode(0);

$this->assertFalse($this->serviceAlias->existAlias(['phpunit'], ['alias'], '1.0.0'));
}
}
33 changes: 33 additions & 0 deletions tests/integration/Console/Commands/Index/CreateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Tests\Integration\Console\Commands\Index;

use Tests\IntegrationTestCase;
use Triadev\Es\Contract\ElasticsearchIndexContract;

class CreateTest extends IntegrationTestCase
{
/** @var ElasticsearchIndexContract */
private $service;

public function setUp()
{
parent::setUp();

$this->service = app(ElasticsearchIndexContract::class);
}

/**
* @test
*/
public function it_creates_an_index()
{
$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($this->service->existIndex([
'phpunit'
], '1.0.0'));
}
}
42 changes: 42 additions & 0 deletions tests/integration/Console/Commands/Index/DeleteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace Tests\Integration\Console\Commands\Index;

use Tests\IntegrationTestCase;
use Triadev\Es\Contract\ElasticsearchIndexContract;

class DeleteTest extends IntegrationTestCase
{
/** @var ElasticsearchIndexContract */
private $service;

public function setUp()
{
parent::setUp();

$this->service = app(ElasticsearchIndexContract::class);
}

/**
* @test
*/
public function it_deletes_an_index()
{
$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($this->service->existIndex([
'phpunit'
], '1.0.0'));

$this->artisan('triadev:es:index:delete', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertFalse($this->service->existIndex([
'phpunit'
], '1.0.0'));
}
}
35 changes: 35 additions & 0 deletions tests/integration/Console/Commands/Version/OverviewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Tests\Integration\Console\Commands\Version;

use Tests\IntegrationTestCase;
use Triadev\Es\Contract\ElasticsearchIndexContract;

class OverviewTest extends IntegrationTestCase
{
/** @var ElasticsearchIndexContract */
private $service;

public function setUp()
{
parent::setUp();

$this->service = app(ElasticsearchIndexContract::class);
}

/**
* @test
*/
public function it_gets_all_index_versions()
{
$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($this->service->existIndex([
'phpunit'
], '1.0.0'));

$this->artisan('triadev:es:version:overview', ['index' => 'phpunit'])->assertExitCode(0);
}
}
7 changes: 4 additions & 3 deletions tests/integration/ElasticsearchAliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public function setUp()

$indexService->deleteAllIndexes();

$indexService->createIndex('phpunit', [
'body' => $this->getMapping()
], '1.0.0');
$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($indexService->existIndex(['phpunit'], '1.0.0'));

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/ElasticsearchDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public function setUp()

$indexService->deleteAllIndexes();

$indexService->createIndex('phpunit', [
'body' => $this->getMapping()
], '1.0.0');
$this->artisan('triadev:es:index:create', [
'index' => 'phpunit',
'version' => '1.0.0'
]);

$this->assertTrue($indexService->existIndex(['phpunit'], '1.0.0'));

Expand Down

0 comments on commit 502c544

Please sign in to comment.