File tree Expand file tree Collapse file tree 12 files changed +209
-21
lines changed Expand file tree Collapse file tree 12 files changed +209
-21
lines changed Original file line number Diff line number Diff line change 2
2
3
3
All notable changes to ` laravel-elastica-bridge ` will be documented in this file.
4
4
5
+ ## 1.1.0 - UNRELEASED
6
+
7
+ - provide default implementation for ` Limenet\LaravelElasticaBridge\Model\ElasticsearchableInterface\toElasticsearch `
8
+ - added tests
9
+
5
10
## 1.0.0 - 2021-05-09
6
11
7
12
- initial release
Original file line number Diff line number Diff line change 37
37
},
38
38
"autoload-dev" : {
39
39
"psr-4" : {
40
- "Limenet\\ LaravelElasticaBridge\\ Tests\\ " : " tests"
40
+ "Limenet\\ LaravelElasticaBridge\\ Tests\\ " : " tests" ,
41
+ "Limenet\\ LaravelElasticaBridge\\ Tests\\ Database\\ Factories\\ " : " tests/database/factories" ,
42
+ "Limenet\\ LaravelElasticaBridge\\ Tests\\ Database\\ Seeders\\ " : " tests/database/seeders"
41
43
}
42
44
},
43
45
"scripts" : {
44
46
"psalm" : " vendor/bin/psalm" ,
45
47
"test" : " ./vendor/bin/testbench package:test --parallel --no-coverage" ,
46
- "test-coverage" : " vendor/bin/phpunit --coverage-html coverage"
48
+ "test-coverage" : " XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html coverage" ,
49
+ "code-swift" : " docker exec -it --user=laradock -w /var/www/$(git rev-parse --show-toplevel | xargs basename | cat) $(docker ps -q --filter name=laradock_workspace-8.0_) zsh"
47
50
},
48
51
"config" : {
49
52
"sort-packages" : true
Original file line number Diff line number Diff line change 23
23
<directory >tests</directory >
24
24
</testsuite >
25
25
</testsuites >
26
- <coverage >
26
+ <coverage
27
+ includeUncoveredFiles =" true"
28
+ processUncoveredFiles =" true"
29
+ pathCoverage =" true"
30
+ >
27
31
<include >
28
32
<directory suffix =" .php" >./src</directory >
29
33
</include >
Original file line number Diff line number Diff line change
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
+
9
+ class CustomerIndex extends AbstractIndex {
10
+
11
+ public function getName (): string { return 'testing_customer ' ; }
12
+
13
+ public function getAllowedDocuments (): array {
14
+ return [Customer::class];
15
+ }
16
+
17
+ public function getMapping (): array
18
+ {
19
+ return [
20
+ 'properties ' => [
21
+ 'group ' => [
22
+ 'type ' => 'keyword ' ,
23
+ ],
24
+ ]
25
+ ];
26
+ }
27
+ }
Original file line number Diff line number Diff line change
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 \CustomerFactory ;
12
+
13
+ class Customer extends Model implements ElasticsearchableInterface{
14
+ use HasFactory;
15
+ use ElasticsearchableTrait;
16
+
17
+ public function toElasticsearch (IndexInterface $ indexConfig ): array { return $ this ->toArray (); }
18
+
19
+ public function shouldIndex (IndexInterface $ indexConfig ): bool { return true ;}
20
+ protected static function newFactory ():Factory
21
+ {
22
+ return CustomerFactory::new ();
23
+ }
24
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Limenet \LaravelElasticaBridge \Tests ;
4
+
5
+ use Elastica \Document ;
6
+ use Limenet \LaravelElasticaBridge \Tests \App \Elasticsearch \CustomerIndex ;
7
+ use Limenet \LaravelElasticaBridge \Tests \App \Models \Customer ;
8
+
9
+ class IndexTest extends TestCase
10
+ {
11
+ protected CustomerIndex $ customerIndex ;
12
+
13
+ public function setUp ():void {
14
+
15
+ parent ::setUp ();
16
+
17
+ $ this ->customerIndex = $ this ->app ->make (CustomerIndex::class);
18
+ }
19
+ /** @test */
20
+ public function index_settings ()
21
+ {
22
+ $ settings =$ this ->customerIndex ->getCreateArguments ();
23
+ if ($ this ->customerIndex ->hasMapping ()){
24
+ $ this ->assertArrayHasKey ('mappings ' ,$ settings );
25
+ }
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Limenet \LaravelElasticaBridge \Tests ;
4
+
5
+ use Elastica \Document ;
6
+ use Limenet \LaravelElasticaBridge \Tests \App \Elasticsearch \CustomerIndex ;
7
+ use Limenet \LaravelElasticaBridge \Tests \App \Models \Customer ;
8
+
9
+ class ModelTest extends TestCase
10
+ {
11
+ protected CustomerIndex $ customerIndex ;
12
+
13
+ public function setUp ():void {
14
+
15
+ parent ::setUp ();
16
+
17
+ $ this ->customerIndex = $ this ->app ->make (CustomerIndex::class);
18
+ }
19
+ /** @test */
20
+ public function convert_to_elastica_document ()
21
+ {
22
+ /** @var Customer $customer */
23
+ $ customer =Customer::first ();
24
+ $ document = $ customer ->toElasticaDocument ($ this ->customerIndex );
25
+ $ this ->assertInstanceOf (Document::class, $ document );
26
+
27
+ $ this ->assertSame ($ customer ->name ,$ document ->get ('name ' ));
28
+ $ this ->assertSame ($ customer ->email ,$ document ->get ('email ' ));
29
+ }
30
+ }
Original file line number Diff line number Diff line change 3
3
namespace Limenet \LaravelElasticaBridge \Tests ;
4
4
5
5
use Illuminate \Database \Eloquent \Factories \Factory ;
6
+ use Illuminate \Foundation \Testing \RefreshDatabase ;
6
7
use Limenet \LaravelElasticaBridge \LaravelElasticaBridgeServiceProvider ;
8
+ use Limenet \LaravelElasticaBridge \Tests \Database \Seeders \DatabaseSeeder ;
7
9
use Orchestra \Testbench \TestCase as Orchestra ;
10
+ use SetupTables ;
8
11
9
12
class TestCase extends Orchestra
10
13
{
14
+ // use RefreshDatabase;
11
15
public function setUp (): void
12
16
{
13
17
parent ::setUp ();
14
18
15
19
Factory::guessFactoryNamesUsing (
16
- fn (string $ modelName ) => 'Spatie \\LaravelElasticaBridge \\Database \\Factories \\' .class_basename ($ modelName ).'Factory '
20
+ fn (string $ modelName ) => 'Limenet \\LaravelElasticaBridge \\ Tests \\Database \\Factories \\' .class_basename ($ modelName ).'Factory '
17
21
);
18
22
}
19
23
@@ -27,10 +31,11 @@ protected function getPackageProviders($app)
27
31
public function getEnvironmentSetUp ($ app )
28
32
{
29
33
config ()->set ('database.default ' , 'testing ' );
30
-
31
- /*
32
- include_once __DIR__.'/../database/migrations/create_laravel-elastica-bridge_table.php.stub';
33
- (new \CreatePackageTable())->up();
34
- */
34
+ }
35
+ protected function defineDatabaseMigrations ():void
36
+ {
37
+ include_once __DIR__ .'/database/migrations/SetupTables.php ' ;
38
+ (new SetupTables ())->up ();
39
+ $ this ->artisan ('db:seed ' , ['--class ' => DatabaseSeeder::class])->run ();
35
40
}
36
41
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Limenet \LaravelElasticaBridge \Tests \Database \Factories ;
4
+
5
+ use App \Models \User ;
6
+ use Illuminate \Database \Eloquent \Factories \Factory ;
7
+ use Illuminate \Support \Str ;
8
+ use Limenet \LaravelElasticaBridge \Tests \App \Models \Customer ;
9
+
10
+ class CustomerFactory extends Factory
11
+ {
12
+ /**
13
+ * The name of the factory's corresponding model.
14
+ *
15
+ * @var string
16
+ */
17
+ protected $ model = Customer::class;
18
+
19
+ /**
20
+ * Define the model's default state.
21
+ *
22
+ * @return array
23
+ */
24
+ public function definition ()
25
+ {
26
+ return [
27
+ 'name ' => $ this ->faker ->name (),
28
+ 'email ' => $ this ->faker ->unique ()->safeEmail (),
29
+ 'type ' =>$ this ->faker ->randomElement (['small ' ,'medium ' ,'big ' ])
30
+ ];
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments