Skip to content

Commit

Permalink
test: fix intermittent view model test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley committed Feb 4, 2025
1 parent 34a67ee commit 7c5b646
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/Unit/ViewModels/ViewModelFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\ViewModels\TransactionViewModel;
use App\ViewModels\ViewModelFactory;
use App\ViewModels\WalletViewModel;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Tests\InvalidModel;

Expand All @@ -27,7 +28,16 @@
]);

it('should make a view model collection', function ($modelClass, $viewModel) {
$models = $modelClass::factory(10)->create();
$models = new EloquentCollection();
for ($i = 0; $i < 10; $i++) {
try {
$models->add($modelClass::factory()->create());
} catch (\Exception $e) {
if (str_contains($e->getMessage(), 'duplicate key value violates')) {
$i--;
}
}
}

expect(ViewModelFactory::collection($models))->toBeInstanceOf(Collection::class);

Expand Down

0 comments on commit 7c5b646

Please sign in to comment.