adrema/database/factories/Payment/PaymentFactory.php

61 lines
1.5 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;
2023-11-30 23:54:16 +01:00
use Illuminate\Support\Carbon;
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,
2023-11-30 23:54:16 +01:00
'last_remembered_at' => now(),
];
}
public function notPaid(): self
{
return $this->for(Status::whereName('Nicht bezahlt')->first());
}
2023-11-30 23:54:16 +01:00
public function pending(): self
{
return $this->for(Status::whereName('Rechnung gestellt')->first())->state(['last_remembered_at' => now()->subYears(2)]);;
}
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)
);
}
}