adrema/tests/RequestFactories/SubscriptionRequestFactory.php

53 lines
1.2 KiB
PHP
Raw Normal View History

2022-12-13 21:21:08 +01:00
<?php
namespace Tests\RequestFactories;
use App\Fee;
use Worksome\RequestFactories\RequestFactory;
class SubscriptionRequestFactory extends RequestFactory
{
2022-12-13 23:11:32 +01:00
/**
2023-12-20 22:11:07 +01:00
* @return array{fee_id: int, name: string, children: array<int, array{amount: int, name: string}>}
2022-12-13 23:11:32 +01:00
*/
2022-12-13 21:21:08 +01:00
public function definition(): array
{
return [
'fee_id' => Fee::factory()->create()->id,
'name' => $this->faker->words(5, true),
2022-12-13 23:11:32 +01:00
'children' => [],
2022-12-13 21:21:08 +01:00
];
}
public function amount(int $amount): self
{
return $this->state(['amount' => $amount]);
}
public function fee(Fee $fee): self
{
return $this->state(['fee_id' => $fee->id]);
}
public function name(string $name): self
{
return $this->state(['name' => $name]);
}
public function invalid(): self
{
return $this->state([
'fee_id' => 9999,
'name' => '',
]);
}
2022-12-13 23:11:32 +01:00
/**
* @param array<int, Child> $children
*/
public function children(array $children): self
{
return $this->state(['children' => array_map(fn ($child) => $child->toArray(), $children)]);
}
2022-12-13 21:21:08 +01:00
}