diff --git a/database/factories/Member/MemberFactory.php b/database/factories/Member/MemberFactory.php index e7fcbed7..3778ac05 100644 --- a/database/factories/Member/MemberFactory.php +++ b/database/factories/Member/MemberFactory.php @@ -7,6 +7,7 @@ use App\Fee; use App\Group; use App\Member\Member; use App\Nationality; +use App\Payment\Payment; use App\Payment\Subscription; use Illuminate\Database\Eloquent\Factories\Factory; @@ -60,4 +61,15 @@ class MemberFactory extends Factory ->for($subscription); } + public function withPayments(array $payments): self + { + return $this->afterCreating(function (Member $model) use ($payments): void { + foreach ($payments as $paymentClosure) { + $factory = Payment::factory()->for($model); + $factory = call_user_func($paymentClosure, $factory); + $factory->create(); + } + }); + } + } diff --git a/tests/Feature/Pdf/GenerateTest.php b/tests/Feature/Pdf/GenerateTest.php index 2edff6fa..537a41e9 100644 --- a/tests/Feature/Pdf/GenerateTest.php +++ b/tests/Feature/Pdf/GenerateTest.php @@ -140,16 +140,11 @@ class GenerateTest extends TestCase $memberFactory = Member::factory() ->for(Nationality::factory()) ->for(Subscription::factory()->for(Fee::factory())) + ->withPayments(data_get($member, 'payments', [])) ->forCountry(Country::find(5)) ->for(Group::factory()); $memberModel = call_user_func($member['factory'], $memberFactory)->create(); - foreach (data_get($member, 'payments', []) as $payment) { - $paymentFactory = Payment::factory()->for($memberModel); - $paymentFactory = call_user_func($payment, $paymentFactory); - $paymentFactory->create(); - } - return $memberModel->load('payments'); }); }