Skip to content

Commit 5536c5d

Browse files
committed
more tests
1 parent 22de240 commit 5536c5d

File tree

13 files changed

+182
-6
lines changed

13 files changed

+182
-6
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@
4040
<logging>
4141
<junit outputFile="build/report.junit.xml"/>
4242
</logging>
43+
<php>
44+
<env name="ELASTICSEARCH_HOST" value="code.swift"/>
45+
</php>
4346
</phpunit>

testbench.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
providers:
22
- Limenet\LaravelElasticaBridge\LaravelElasticaBridgeServiceProvider
3+
env:
4+
- ELASTICSEARCH_HOST="code.swift"

tests/App/Elasticsearch/AllIndex.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
4+
namespace Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch;
5+
6+
use Limenet\LaravelElasticaBridge\Index\AbstractIndex;
7+
use Limenet\LaravelElasticaBridge\Tests\App\Models\Customer;
8+
use Limenet\LaravelElasticaBridge\Tests\App\Models\Product;
9+
10+
class ProductIndex extends AbstractIndex
11+
{
12+
public function getName(): string
13+
{
14+
return 'testing_product';
15+
}
16+
17+
public function getAllowedDocuments(): array
18+
{
19+
return [Customer::class, Product::class];
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
4+
namespace Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch;
5+
6+
use Limenet\LaravelElasticaBridge\Index\AbstractIndex;
7+
use Limenet\LaravelElasticaBridge\Tests\App\Models\Product;
8+
9+
class ProductIndex extends AbstractIndex
10+
{
11+
public function getName(): string
12+
{
13+
return 'testing_product';
14+
}
15+
16+
public function getAllowedDocuments(): array
17+
{
18+
return [Product::class];
19+
}
20+
}

tests/App/Models/Customer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function shouldIndex(IndexInterface $indexConfig): bool
2424
{
2525
return true;
2626
}
27-
protected static function newFactory():Factory
27+
28+
protected static function newFactory(): Factory
2829
{
2930
return CustomerFactory::new();
3031
}

tests/App/Models/Product.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Limenet\LaravelElasticaBridge\Tests\App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Limenet\LaravelElasticaBridge\Index\IndexInterface;
9+
use Limenet\LaravelElasticaBridge\Model\ElasticsearchableInterface;
10+
use Limenet\LaravelElasticaBridge\Model\ElasticsearchableTrait;
11+
use Limenet\LaravelElasticaBridge\Tests\Database\Factories\ProductFactory;
12+
13+
class Product extends Model implements ElasticsearchableInterface
14+
{
15+
use HasFactory;
16+
use ElasticsearchableTrait;
17+
18+
public function shouldIndex(IndexInterface $indexConfig): bool
19+
{
20+
return true;
21+
}
22+
23+
protected static function newFactory(): Factory
24+
{
25+
return ProductFactory::new();
26+
}
27+
}

tests/Feature/FeatureTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Limenet\LaravelElasticaBridge\Tests\Feature;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Limenet\LaravelElasticaBridge\LaravelElasticaBridgeServiceProvider;
7+
use Limenet\LaravelElasticaBridge\Repository\IndexRepository;
8+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
9+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\ProductIndex;
10+
use Limenet\LaravelElasticaBridge\Tests\Database\Seeders\DatabaseSeeder;
11+
use Orchestra\Testbench\TestCase as Orchestra;
12+
use SetupTables;
13+
14+
class FeatureTest extends TestCase
15+
{
16+
17+
/** @test */
18+
public function index_repository()
19+
{
20+
$this->assertCount(2, $this->indexRepository->all());
21+
$this->assertInstanceOf(CustomerIndex::class, $this->indexRepository->get($this->customerIndex::class));
22+
}
23+
}

tests/Feature/TestCase.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Limenet\LaravelElasticaBridge\Tests\Feature;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Limenet\LaravelElasticaBridge\LaravelElasticaBridgeServiceProvider;
7+
use Limenet\LaravelElasticaBridge\Repository\IndexRepository;
8+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
9+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\ProductIndex;
10+
use Limenet\LaravelElasticaBridge\Tests\Database\Seeders\DatabaseSeeder;
11+
use Orchestra\Testbench\TestCase as Orchestra;
12+
use SetupTables;
13+
14+
class TestCase extends Orchestra
15+
{
16+
protected CustomerIndex $customerIndex;
17+
protected ProductIndex $productIndex;
18+
protected IndexRepository $indexRepository;
19+
public function setUp(): void
20+
{
21+
parent::setUp();
22+
23+
$this->customerIndex = $this->app->make(CustomerIndex::class);
24+
$this->productIndex = $this->app->make(ProductIndex::class);
25+
$this->indexRepository = new IndexRepository([
26+
$this->customerIndex::class=>$this->customerIndex,
27+
$this->productIndex::class=>$this->productIndex,
28+
]);
29+
}
30+
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getEnvironmentSetUp($app)
3030
{
3131
config()->set('database.default', 'testing');
3232

33-
config()->set('elastica-bridge.elasticseach.host', 'localhost');
33+
config()->set('elastica-bridge.elasticseach.host', env('ELASTICSEARCH_HOST', 'localhost'));
3434
config()->set('elastica-bridge.elasticseach.port', 9200);
3535
}
3636

tests/Unit/IndexTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
use Elastica\Index;
66
use Limenet\LaravelElasticaBridge\Exception\Index\BlueGreenIndicesIncorrectlySetupException;
77
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
8+
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\ProductIndex;
89
use Limenet\LaravelElasticaBridge\Tests\App\Models\Customer;
910
use RuntimeException;
1011

1112
class IndexTest extends TestCase
1213
{
1314
protected CustomerIndex $customerIndex;
15+
protected ProductIndex $productIndex;
1416

1517
public function setUp():void
1618
{
1719
parent::setUp();
1820

1921
$this->customerIndex = $this->app->make(CustomerIndex::class);
22+
$this->productIndex = $this->app->make(ProductIndex::class);
2023
}
2124
/** @test */
2225
public function raw_index()
@@ -28,15 +31,26 @@ public function raw_index()
2831
}
2932

3033
/** @test */
31-
public function settings()
34+
public function settings_customized()
3235
{
3336
$settings = $this->customerIndex->getCreateArguments();
3437
$mappings = $this->customerIndex->getMapping();
3538

3639
$this->assertTrue($this->customerIndex->hasMapping());
3740
$this->assertArrayHasKey('mappings', $settings);
41+
$this->assertArrayNotHasKey('settings', $settings);
3842
$this->assertSame($settings['mappings'], $mappings);
3943
}
44+
/** @test */
45+
public function settings_Default()
46+
{
47+
$settings = $this->productIndex->getCreateArguments();
48+
$mappings = $this->productIndex->getMapping();
49+
50+
$this->assertFalse($this->productIndex->hasMapping());
51+
$this->assertEmpty($mappings);
52+
$this->assertEmpty($settings);
53+
}
4054

4155
/** @test */
4256
public function document_to_model()

0 commit comments

Comments
 (0)