adrema/tests/Feature/Invoice/InvoiceRequestFactory.php

56 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2023-12-13 00:35:39 +01:00
<?php
namespace Tests\Feature\Invoice;
2023-12-16 11:18:00 +01:00
use App\Invoice\BillKind;
2023-12-13 00:35:39 +01:00
use App\Invoice\Enums\InvoiceStatus;
use Worksome\RequestFactories\RequestFactory;
class InvoiceRequestFactory extends RequestFactory
{
2023-12-17 00:45:03 +01:00
/** @var array<int, InvoicePositionRequestFactory> */
public $positions = [];
2023-12-13 00:35:39 +01:00
public function definition(): array
{
return [
'to' => ReceiverRequestFactory::new(),
'greeting' => 'Hallo Familie',
2023-12-17 00:45:03 +01:00
'status' => InvoiceStatus::NEW->value,
'via' => BillKind::EMAIL->value,
2023-12-17 23:00:52 +01:00
'positions' => [],
'usage' => $this->faker->words(4, true),
2023-12-13 00:35:39 +01:00
];
}
public function to(ReceiverRequestFactory $to): self
{
return $this->state(['to' => $to]);
}
public function status(InvoiceStatus $status): self
{
return $this->state(['status' => $status->value]);
}
public function position(InvoicePositionRequestFactory $factory): self
{
2023-12-17 00:45:03 +01:00
$this->positions[] = $factory;
return $this;
}
public function create(array $attributes = []): array
{
return parent::create([
'positions' => array_map(fn ($position) => $position->create(), $this->positions),
...$attributes,
]);
2023-12-13 00:35:39 +01:00
}
2023-12-16 11:18:00 +01:00
public function via(BillKind $via): self
{
return $this->state(['via' => $via->value]);
}
2023-12-13 00:35:39 +01:00
}