File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Elastica \Index ;
6
6
use Limenet \LaravelElasticaBridge \Tests \App \Elasticsearch \CustomerIndex ;
7
+ use Limenet \LaravelElasticaBridge \Tests \App \Models \Customer ;
8
+ use RuntimeException ;
7
9
8
10
class IndexTest extends TestCase
9
11
{
@@ -34,4 +36,26 @@ public function settings()
34
36
$ this ->assertArrayHasKey ('mappings ' , $ settings );
35
37
$ this ->assertSame ($ settings ['mappings ' ], $ mappings );
36
38
}
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
+ }
37
61
}
You can’t perform that action at this time.
0 commit comments