This commit is contained in:
philipp lang 2024-02-09 00:21:33 +01:00
parent 857051434e
commit a0bcd99642
10 changed files with 42 additions and 14 deletions

View File

@ -79,7 +79,9 @@ abstract class Field extends Data
*/
public function presentValue($value)
{
return [$this->key => $value];
return [
$this->key => $value,
];
}
/**

View File

@ -4,15 +4,19 @@ namespace App\Form\Resources;
use App\Form\Fields\Field;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Participant
*/
class ParticipantResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
* @return array<string, mixed>
*/
public function toArray($request)
{
@ -22,9 +26,12 @@ class ParticipantResource extends JsonResource
$attributes = $attributes->merge(Field::fromConfig($field)->presentValue($this->data[$field['key']]));
}
return $attributes;
return $attributes->toArray();
}
/**
* @return array<string, mixed>
*/
public static function meta(Form $form): array
{
return [

View File

@ -2,7 +2,6 @@
namespace Database\Factories\Form\Models;
use App\Form\Models\Form;
use App\Form\Models\Participant;
use Illuminate\Database\Eloquent\Factories\Factory;
use Tests\Feature\Form\FormtemplateSectionRequest;
@ -15,7 +14,7 @@ class ParticipantFactory extends Factory
/**
* The name of the factory's corresponding model.
*
* @var class-string<Form>
* @var class-string<Participant>
*/
protected $model = Participant::class;

View File

@ -8,7 +8,7 @@ use Spatie\MediaLibrary\HasMedia;
trait FakesMedia
{
public function withImage(string $collection, $filename): self
public function withImage(string $collection, string $filename): self
{
return $this->afterCreating(function (HasMedia $model) use ($filename, $collection) {
$pathinfo = pathinfo($filename);

View File

@ -532,3 +532,18 @@ parameters:
message: "#^Parameter \\#1 \\.\\.\\.\\$parts of method App\\\\Member\\\\FilterScope\\:\\:combinations\\(\\) expects array\\<int, int\\>, array\\<int, array\\<int, int\\>\\> given\\.$#"
count: 1
path: app/Member/FilterScope.php
-
message: "#^Call to function is_null\\(\\) with array will always evaluate to false\\.$#"
count: 1
path: app/Form/Models/Form.php
-
message: "#^Unable to resolve the template type TKey in call to function collect$#"
count: 1
path: app/Form/Models/Form.php
-
message: "#^Unable to resolve the template type TValue in call to function collect$#"
count: 1
path: app/Form/Models/Form.php

View File

@ -63,7 +63,7 @@ class FormIndexActionTest extends EndToEndTestCase
->assertInertiaPath('data.meta.section_default.name', '');
}
public function testItHandlesFullTextSearch()
public function testItHandlesFullTextSearch(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
@ -76,7 +76,7 @@ class FormIndexActionTest extends EndToEndTestCase
->assertInertiaCount('data.data', 2);
}
public function testItOrdersByStartDateDesc()
public function testItOrdersByStartDateDesc(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create();
@ -90,7 +90,7 @@ class FormIndexActionTest extends EndToEndTestCase
->assertInertiaPath('data.data.2.id', $form1->id);
}
public function testItShowsPastEvents()
public function testItShowsPastEvents(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
Form::factory()->count(5)->to(now()->subDays(2))->create();

View File

@ -56,6 +56,8 @@ class FormRegisterActionTest extends TestCase
/**
* @dataProvider validationDataProvider
* @param array<string, mixed> $payload
* @param ?array<string, mixed> $messages
*/
public function testItValidatesInput(FormtemplateFieldRequest $fieldGenerator, array $payload, ?array $messages): void
{
@ -73,7 +75,7 @@ class FormRegisterActionTest extends TestCase
}
}
private function validationDataProvider(): Generator
public function validationDataProvider(): Generator
{
yield [
FormtemplateFieldRequest::type(DateField::class)->name('Geburtsdatum')->maxToday(false)->key('birthday'),
@ -89,7 +91,7 @@ class FormRegisterActionTest extends TestCase
yield [
FormtemplateFieldRequest::type(DateField::class)->name('Geburtsdatum')->maxToday(true)->key('birthday'),
['birthday' => now()->addDay(1)->format('Y-m-d')],
['birthday' => now()->addDay()->format('Y-m-d')],
['birthday' => 'Geburtsdatum muss ein Datum vor oder gleich dem ' . now()->format('d.m.Y') . ' sein.'],
];

View File

@ -31,7 +31,7 @@ class FormStoreActionTest extends TestCase
$description = EditorRequestFactory::new()->text(10, 'Lorem');
FormRequest::new()
->name('formname')
->description($description->create())
->description($description)
->excerpt('avff')
->registrationFrom('2023-05-04 01:00:00')->registrationUntil('2023-07-07 01:00:00')->from('2023-07-07')->to('2023-07-08')
->mailTop('Guten Tag')

View File

@ -14,6 +14,8 @@ use Worksome\RequestFactories\RequestFactory;
* @method self default(mixed $default)
* @method self options(array<int, string> $options)
* @method self maxToday(bool $maxToday)
* @method self parentGroup(int $groupId)
* @method self parentField(string $fieldKey)
*/
class FormtemplateFieldRequest extends RequestFactory
{

View File

@ -2,8 +2,6 @@
namespace Tests\RequestFactories;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Worksome\RequestFactories\RequestFactory;
class EditorRequestFactory extends RequestFactory
@ -27,6 +25,9 @@ class EditorRequestFactory extends RequestFactory
return $this->state($this->paragraphBlock($id, $text));
}
/**
* @return array<string, mixed>
*/
public function paragraphBlock(int $id, string $text): array
{
return [