Skip to content

Commit a6f2335

Browse files
committed
more tests
1 parent 4c279f6 commit a6f2335

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

tests/Feature/FeatureTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ class FeatureTest extends TestCase
88
{
99

1010
/** @test */
11-
public function index_repository()
11+
public function status()
1212
{
13-
$this->assertCount(2, $this->indexRepository->all());
14-
$this->assertInstanceOf(CustomerIndex::class, $this->indexRepository->get($this->customerIndex::class));
13+
$this->assertSame(0, $this->artisan('elastica-bridge:status')->run());
1514
}
1615
}

tests/Feature/TestCase.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Limenet\LaravelElasticaBridge\Tests\Feature;
44

5+
use Limenet\LaravelElasticaBridge\Client\ElasticaClient;
56
use Limenet\LaravelElasticaBridge\Repository\IndexRepository;
67
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
78
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\ProductIndex;
@@ -18,9 +19,6 @@ public function setUp(): void
1819

1920
$this->customerIndex = $this->app->make(CustomerIndex::class);
2021
$this->productIndex = $this->app->make(ProductIndex::class);
21-
$this->indexRepository = new IndexRepository([
22-
$this->customerIndex::class => $this->customerIndex,
23-
$this->productIndex::class => $this->productIndex,
24-
]);
22+
$this->indexRepository =$this->app->make(IndexRepository::class);
2523
}
2624
}

tests/TestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
66
use Limenet\LaravelElasticaBridge\LaravelElasticaBridgeServiceProvider;
7+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
8+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\ProductIndex;
79
use Limenet\LaravelElasticaBridge\Tests\Database\Seeders\DatabaseSeeder;
810
use Orchestra\Testbench\TestCase as Orchestra;
911
use SetupTables;
@@ -18,6 +20,11 @@ public function setUp(): void
1820
fn (string $modelName) => 'Limenet\\LaravelElasticaBridge\\Tests\\Database\\Factories\\'.class_basename($modelName).'Factory'
1921
);
2022
}
23+
protected function resolveApplicationConfiguration($app){
24+
parent::resolveApplicationConfiguration($app);
25+
26+
$app['config']->set('elastica-bridge.indices', [CustomerIndex::class,ProductIndex::class]);
27+
}
2128

2229
protected function getPackageProviders($app)
2330
{

tests/Unit/RepositoryTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Limenet\LaravelElasticaBridge\Tests\Unit;
4+
5+
use Elastica\Index;
6+
use Elastica\Query;
7+
use Elastica\Response;
8+
use Elastica\ResultSet;
9+
use Limenet\LaravelElasticaBridge\Exception\Index\BlueGreenIndicesIncorrectlySetupException;
10+
use Limenet\LaravelElasticaBridge\Index\IndexInterface;
11+
use Limenet\LaravelElasticaBridge\Repository\IndexRepository;
12+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
13+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\ProductIndex;
14+
use Limenet\LaravelElasticaBridge\Tests\App\Models\Customer;
15+
use RuntimeException;
16+
17+
class RepositoryTest extends TestCase
18+
{
19+
protected CustomerIndex $customerIndex;
20+
protected ProductIndex $productIndex;
21+
protected IndexRepository $indexRepository;
22+
23+
public function setUp():void
24+
{
25+
parent::setUp();
26+
27+
$this->customerIndex = $this->app->make(CustomerIndex::class);
28+
$this->productIndex = $this->app->make(ProductIndex::class);
29+
$this->indexRepository =$this->app->make(IndexRepository::class);
30+
}
31+
/** @test */
32+
public function all()
33+
{
34+
$this->assertCount(2, $this->indexRepository->all());
35+
foreach($this->indexRepository->all() as $index){
36+
$this->assertInstanceOf(IndexInterface::class, $index);
37+
}
38+
}
39+
/** @test */
40+
public function single()
41+
{
42+
$this->assertInstanceOf(CustomerIndex::class, $this->indexRepository->get($this->customerIndex::class));
43+
$this->assertInstanceOf(ProductIndex::class, $this->indexRepository->get($this->productIndex::class));
44+
}
45+
}

0 commit comments

Comments
 (0)