5
5
use Elastica \Document ;
6
6
use Limenet \LaravelElasticaBridge \Index \IndexInterface ;
7
7
use Limenet \LaravelElasticaBridge \Tests \App \Elasticsearch \CustomerIndex ;
8
+ use Limenet \LaravelElasticaBridge \Tests \App \Elasticsearch \ProductIndex ;
8
9
use Limenet \LaravelElasticaBridge \Tests \App \Models \Customer ;
10
+ use Limenet \LaravelElasticaBridge \Tests \App \Models \Product ;
9
11
10
12
class ModelTest extends TestCase
11
13
{
12
14
protected CustomerIndex $ customerIndex ;
15
+ protected ProductIndex $ productIndex ;
13
16
14
17
public function setUp ():void
15
18
{
16
19
parent ::setUp ();
17
20
18
21
$ this ->customerIndex = $ this ->app ->make (CustomerIndex::class);
22
+ $ this ->productIndex = $ this ->app ->make (ProductIndex::class);
19
23
}
20
24
/** @test */
21
- public function convert_to_elastica_document ()
25
+ public function convert_to_elastica_document_customized ()
22
26
{
23
27
Customer::all ()
28
+ ->filter (fn (Customer $ customer ):bool =>$ customer ->shouldIndex ($ this ->customerIndex ))
24
29
->each (function (Customer $ customer ):void {
25
30
$ document = $ customer ->toElasticaDocument ($ this ->customerIndex );
26
31
$ this ->assertInstanceOf (Document::class, $ document );
@@ -36,4 +41,22 @@ public function convert_to_elastica_document()
36
41
$ this ->assertSame ($ customer ::class, $ document ->get (IndexInterface::DOCUMENT_MODEL_CLASS ));
37
42
});
38
43
}
44
+ /** @test */
45
+ public function convert_to_elastica_document_default ()
46
+ {
47
+ Product::all ()
48
+ ->filter (fn (Product $ product ):bool =>$ product ->shouldIndex ($ this ->productIndex ))
49
+ ->each (function (Product $ product ):void {
50
+ $ document = $ product ->toElasticaDocument ($ this ->productIndex );
51
+ $ this ->assertInstanceOf (Document::class, $ document );
52
+
53
+ $ this ->assertSame ($ product ->name , $ document ->get ('name ' ));
54
+
55
+ $ this ->assertStringContainsString ('| ' .$ product ->id , $ document ->getId ());
56
+ $ this ->assertStringContainsString ($ product ::class . '| ' , $ document ->getId ());
57
+
58
+ $ this ->assertSame ($ product ->id , $ document ->get (IndexInterface::DOCUMENT_MODEL_ID ));
59
+ $ this ->assertSame ($ product ::class, $ document ->get (IndexInterface::DOCUMENT_MODEL_CLASS ));
60
+ });
61
+ }
39
62
}
0 commit comments