Skip to content

Commit 1c51957

Browse files
committed
more tests
1 parent 5cd5f91 commit 1c51957

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/IndexTest.php

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

55
use Elastica\Index;
66
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
7+
use Limenet\LaravelElasticaBridge\Tests\App\Models\Customer;
8+
use RuntimeException;
79

810
class IndexTest extends TestCase
911
{
@@ -34,4 +36,26 @@ public function settings()
3436
$this->assertArrayHasKey('mappings', $settings);
3537
$this->assertSame($settings['mappings'], $mappings);
3638
}
39+
40+
/** @test */
41+
public function document_to_model()
42+
{
43+
Customer::all()
44+
->each(function (Customer $customer):void {
45+
$document = $customer->toElasticaDocument($this->customerIndex);
46+
$model =$this->customerIndex->getModelInstance($document);
47+
$this->assertInstanceOf(Customer::class, $model);
48+
$this->assertSame($customer->id, $model->id);
49+
});
50+
}
51+
/** @test */
52+
public function empty_document_to_model()
53+
{
54+
/** @var Customer $customer */
55+
$customer = Customer::first();
56+
$document = $customer->toElasticaDocument($this->customerIndex);
57+
$document->setId(null);
58+
$this->expectException(RuntimeException::class);
59+
$this->customerIndex->getModelInstance($document);
60+
}
3761
}

0 commit comments

Comments
 (0)