Skip to content

Commit fa7d936

Browse files
committed
formatting, more assertions
1 parent 1faeb20 commit fa7d936

File tree

7 files changed

+25
-12
lines changed

7 files changed

+25
-12
lines changed

tests/App/Elasticsearch/CustomerIndex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public function getMapping(): array
2626
'type' => 'keyword',
2727
],
2828
],
29-
];
29+
];
3030
}
3131
}

tests/IndexTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function setUp():void
2020
public function raw_index()
2121
{
2222
$index = $this->customerIndex->getElasticaIndex();
23+
2324
$this->assertInstanceOf(Index::class, $index);
2425
$this->assertSame($this->customerIndex->getName(),$index->getName());
2526
}
@@ -29,8 +30,9 @@ public function settings()
2930
{
3031
$settings = $this->customerIndex->getCreateArguments();
3132
$mappings = $this->customerIndex->getMapping();
33+
3234
$this->assertTrue($this->customerIndex->hasMapping());
33-
$this->assertArrayHasKey('mappings', $settings);
34-
$this->assertSame($settings['mappings'],$mappings);
35+
$this->assertArrayHasKey('mappings', $settings);
36+
$this->assertSame($settings['mappings'],$mappings);
3537
}
3638
}

tests/ModelTest.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Limenet\LaravelElasticaBridge\Tests;
44

55
use Elastica\Document;
6+
use Limenet\LaravelElasticaBridge\Index\IndexInterface;
7+
use Limenet\LaravelElasticaBridge\Model\ElasticsearchableInterface;
68
use Limenet\LaravelElasticaBridge\Tests\App\Elasticsearch\CustomerIndex;
79
use Limenet\LaravelElasticaBridge\Tests\App\Models\Customer;
810

@@ -19,12 +21,20 @@ public function setUp():void
1921
/** @test */
2022
public function convert_to_elastica_document()
2123
{
22-
/** @var Customer $customer */
23-
$customer = Customer::first();
24-
$document = $customer->toElasticaDocument($this->customerIndex);
25-
$this->assertInstanceOf(Document::class, $document);
24+
Customer::all()
25+
->each(function(Customer $customer):void{
26+
$document = $customer->toElasticaDocument($this->customerIndex);
27+
$this->assertInstanceOf(Document::class, $document);
2628

27-
$this->assertSame($customer->name, $document->get('name'));
28-
$this->assertSame($customer->email, $document->get('email'));
29+
$this->assertSame($customer->name, $document->get('name'));
30+
$this->assertSame($customer->email, $document->get('email'));
31+
$this->assertSame($customer->type, $document->get('type'));
32+
33+
$this->assertStringContainsString('|'.$customer->id, $document->getId());
34+
$this->assertStringContainsString($customer::class . '|', $document->getId());
35+
36+
$this->assertSame($customer->id, $document->get(IndexInterface::DOCUMENT_MODEL_ID));
37+
$this->assertSame($customer::class, $document->get(IndexInterface::DOCUMENT_MODEL_CLASS));
38+
});
2939
}
3040
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function getEnvironmentSetUp($app)
3333
{
3434
config()->set('database.default', 'testing');
3535
}
36+
3637
protected function defineDatabaseMigrations():void
3738
{
3839
include_once __DIR__.'/database/migrations/SetupTables.php';

tests/database/factories/CustomerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CustomerFactory extends Factory
1919
*
2020
* @return array
2121
*/
22-
public function definition()
22+
public function definition():array
2323
{
2424
return [
2525
'name' => $this->faker->name(),

tests/database/migrations/SetupTables.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class SetupTables extends Migration
88
{
9-
public function up()
9+
public function up():void
1010
{
1111
Schema::create('customers', function (Blueprint $table) {
1212
$table->id();

tests/database/seeders/DatabaseSeeder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DatabaseSeeder extends Seeder
1212
*
1313
* @return void
1414
*/
15-
public function run()
15+
public function run():void
1616
{
1717
Customer::factory()
1818
->count(50)

0 commit comments

Comments
 (0)