2021-07-15 21:14:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Factories\Payment;
|
|
|
|
|
2022-02-12 14:41:46 +01:00
|
|
|
use App\Fee;
|
2021-07-15 21:14:25 +02:00
|
|
|
use App\Payment\Subscription;
|
2022-12-13 23:11:32 +01:00
|
|
|
use App\Payment\SubscriptionChild;
|
2021-07-15 21:14:25 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2022-12-13 23:11:32 +01:00
|
|
|
use Tests\RequestFactories\Child;
|
2021-07-15 21:14:25 +02:00
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
/**
|
|
|
|
* @extends Factory<Subscription>
|
|
|
|
*/
|
2021-07-15 21:14:25 +02:00
|
|
|
class SubscriptionFactory extends Factory
|
|
|
|
{
|
|
|
|
protected $model = Subscription::class;
|
|
|
|
|
|
|
|
public function definition(): array
|
|
|
|
{
|
|
|
|
return [
|
2022-02-12 14:41:46 +01:00
|
|
|
'name' => $this->faker->word,
|
2022-02-12 15:33:16 +01:00
|
|
|
'fee_id' => Fee::factory()->createOne()->id,
|
2022-12-14 15:49:12 +01:00
|
|
|
'for_promise' => false,
|
2021-07-15 21:14:25 +02:00
|
|
|
];
|
|
|
|
}
|
2022-11-22 00:37:34 +01:00
|
|
|
|
|
|
|
public function name(string $name): self
|
|
|
|
{
|
|
|
|
return $this->state(['name' => $name]);
|
|
|
|
}
|
2022-12-13 21:25:03 +01:00
|
|
|
|
2022-12-13 23:11:32 +01:00
|
|
|
/**
|
|
|
|
* @param array<int, Child> $children
|
|
|
|
*/
|
|
|
|
public function children(array $children): self
|
2022-12-13 21:25:03 +01:00
|
|
|
{
|
2022-12-13 23:11:32 +01:00
|
|
|
$instance = $this;
|
|
|
|
|
|
|
|
foreach ($children as $child) {
|
|
|
|
$instance = $instance->has(SubscriptionChild::factory()->state($child->toArray()), 'children');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
2022-12-13 21:25:03 +01:00
|
|
|
}
|
2022-12-14 15:49:12 +01:00
|
|
|
|
|
|
|
public function forPromise(): self
|
|
|
|
{
|
|
|
|
return $this->state(['for_promise' => true]);
|
|
|
|
}
|
2021-07-15 21:14:25 +02:00
|
|
|
}
|