Skip to content

Commit 6cab981

Browse files
committed
test(meta): add comprehensive unit tests for product metadata
- Added new unit tests for `Meta` in `ModelTest.php`. - Ensured metadata properties like `index`, `score`, `highlights`, and `id` are checked. - Enhanced `asArray` method in `ModelMetaData.php` to return array type. Who knew metadata could be so meta? 🧐
1 parent 1c1f9e8 commit 6cab981

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/Eloquent/Model.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,6 @@ public function getForeignKey(): string
276276
return Str::snake(class_basename($this)).'_'.ltrim($this->primaryKey, '_');
277277
}
278278

279-
/**
280-
* {@inheritdoc}
281-
*/
282-
public function newEloquentBuilder($query): Builder
283-
{
284-
$builder = new Builder($query);
285-
286-
return $builder;
287-
}
288-
289279
public function saveWithoutRefresh(array $options = []): bool
290280
{
291281
$this->mergeAttributesFromCachedCasts();

src/Meta/ModelMetaData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function parseHighlights($data = []): ?object
9494
return null;
9595
}
9696

97-
public function asArray()
97+
public function asArray() : array
9898
{
9999
return [
100100
'score' => $this->score,

tests/ModelTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@
132132
$this->assertEquals(35, $check->in_stock);
133133
});
134134

135+
test('Meta', function () {
136+
$product = new Product;
137+
$product['name'] = 'John Doe';
138+
$product['description'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia odio vitae vestibulum vestibulum.';
139+
$product['in_stock'] = 35;
140+
$product['_id'] = "foo-bar";
141+
$product->save();
142+
143+
$check = Product::find($product->id);
144+
145+
$meta = $check->getMeta();
146+
147+
expect($meta)->not()->toBeNull()
148+
->and($meta->getIndex())->not()->toBeNull()
149+
->and($meta->getScore())->not()->toBeNull()
150+
->and($meta->getHighlights())->not()->toBeNull()
151+
->and($meta->getHighlights())->toBeArray()
152+
->and($meta->getId())->toBe('foo-bar')
153+
->and($meta->getQuery())->toBeArray()
154+
->and($meta->asArray())->toBeArray()
155+
;
156+
});
157+
135158
test('Get', function () {
136159
//this also test bulk insert yay!
137160
Product::insert([

0 commit comments

Comments
 (0)