Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jun 13, 2024
1 parent 52bdf64 commit c42a439
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/Fakes/Models/FakeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function fakeNestedModels(): HasMany
return $this->hasMany(FakeNestedModel::class);
}

public function alt_fake_nested_models(): HasMany
public function fake_nested_models_snake_cased(): HasMany
{
return $this->hasMany(FakeNestedModel::class);
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Normalizers/ModelNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
});

it('does not loop infinitely on relations', function () {
$m1 = FakeModel::factory()->makeOne();
$m2 = FakeNestedModel::factory()->makeOne();
$m2->setRelation('parent', $m1);
$m1->setRelation('pivot', $m2);
$parentModel = FakeModel::factory()->makeOne();
$childModel = FakeNestedModel::factory()->makeOne();

$data = FakeModelData::from($m1);
$childModel->setRelation('parent', $parentModel);
$parentModel->setRelation('pivot', $childModel);

expect($m1)
$data = FakeModelData::from($parentModel);

expect($parentModel)
->string->toEqual($data->string)
->nullable->toEqual($data->nullable)
->date->toEqual($data->date);

});

it('can get a data object with nesting from model and relations when loaded', function () {
Expand Down Expand Up @@ -120,10 +120,10 @@
public array $fake_nested_models;

#[LoadRelation, DataCollectionOf(FakeNestedModelData::class)]
public array $alt_fake_nested_models;
public array $fake_nested_models_snake_cased;
};

$model->load('alt_fake_nested_models');
$model->load('fake_nested_models_snake_cased');
DB::enableQueryLog();

$data = $dataClass::from($model);
Expand All @@ -134,7 +134,7 @@
->toHaveCount(2)
->each->toBeInstanceOf(FakeNestedModelData::class);

expect($data->alt_fake_nested_models)
expect($data->fake_nested_models_snake_cased)
->toHaveCount(2)
->each->toBeInstanceOf(FakeNestedModelData::class);
expect($queryLog)->toHaveCount(1);
Expand Down

0 comments on commit c42a439

Please sign in to comment.