adrema/database/factories/Payment/PaymentFactory.php

55 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Database\Factories\Payment;
use App\Fee;
use App\Payment\Payment;
use App\Payment\Status;
use App\Payment\Subscription;
use Illuminate\Database\Eloquent\Factories\Factory;
2022-12-13 23:11:32 +01:00
use Tests\RequestFactories\Child;
2023-02-17 18:57:11 +01:00
/**
* @extends Factory<Payment>
*/
class PaymentFactory extends Factory
{
protected $model = Payment::class;
public function definition(): array
{
return [
2022-02-12 14:41:46 +01:00
'nr' => $this->faker->year,
'subscription_id' => Subscription::factory()->create()->id,
'status_id' => Status::factory()->create()->id,
'last_remembered_at' => $this->faker->dateTime,
];
}
public function notPaid(): self
{
return $this->for(Status::whereName('Nicht bezahlt')->first());
}
2021-07-17 16:57:37 +02:00
public function paid(): self
{
return $this->for(Status::whereName('Rechnung beglichen')->first());
}
public function nr(string $nr): self
{
return $this->state(['nr' => $nr]);
}
2022-12-13 23:11:32 +01:00
/**
2022-12-14 00:23:03 +01:00
* @param array<int, Child> $children
* @param array<string, mixed> $state
2022-12-13 23:11:32 +01:00
*/
2022-12-14 00:23:03 +01:00
public function subscription(string $name, array $children, array $state = []): self
{
return $this->for(
2022-12-14 00:23:03 +01:00
Subscription::factory()->state(['name' => $name])->for(Fee::factory())->children($children)->state($state)
);
}
}