Add Laravel 11 support
continuous-integration/drone/push Build was killed Details

This commit is contained in:
philipp lang 2024-09-21 22:46:38 +02:00
parent fca7fc463e
commit 3a4c99f154
34 changed files with 1273 additions and 1086 deletions

View File

@ -29,7 +29,7 @@ class MemberData extends Data
*/ */
public static function fromModels(array $ids): Collection public static function fromModels(array $ids): Collection
{ {
return Member::whereIn('id', $ids)->orderByRaw('lastname, firstname')->get()->map(fn ($member) => self::withoutMagicalCreationFrom([ return Member::whereIn('id', $ids)->orderByRaw('lastname, firstname')->get()->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
...$member->toArray(), ...$member->toArray(),
'birthday' => $member->birthday->toAtomString(), 'birthday' => $member->birthday->toAtomString(),
'isLeader' => $member->isLeader(), 'isLeader' => $member->isLeader(),
@ -44,7 +44,7 @@ class MemberData extends Data
*/ */
public static function fromApi(array $data): Collection public static function fromApi(array $data): Collection
{ {
return collect($data)->map(fn ($member) => self::withoutMagicalCreationFrom([ return collect($data)->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
...$member, ...$member,
'birthday' => Carbon::parse($member['birthday'])->toAtomString(), 'birthday' => Carbon::parse($member['birthday'])->toAtomString(),
'gender' => Gender::fromString($member['gender']), 'gender' => Gender::fromString($member['gender']),
@ -54,22 +54,22 @@ class MemberData extends Data
public function fullname(): string public function fullname(): string
{ {
return $this->firstname.' '.$this->lastname; return $this->firstname . ' ' . $this->lastname;
} }
public function separatedName(): string public function separatedName(): string
{ {
return $this->lastname.', '.$this->firstname; return $this->lastname . ', ' . $this->firstname;
} }
public function fullAddress(): string public function fullAddress(): string
{ {
return $this->address.', '.$this->zip.' '.$this->location; return $this->address . ', ' . $this->zip . ' ' . $this->location;
} }
public function city(): string public function city(): string
{ {
return $this->zip.' '.$this->location; return $this->zip . ' ' . $this->location;
} }
public function age(): string public function age(): string

View File

@ -6,6 +6,7 @@ use App\Form\Fields\Field;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Spatie\LaravelData\Casts\Cast; use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Data; use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty; use Spatie\LaravelData\Support\DataProperty;
class CollectionCast implements Cast class CollectionCast implements Cast
@ -23,7 +24,7 @@ class CollectionCast implements Cast
* @param array<string, mixed> $context * @param array<string, mixed> $context
* @return Collection<int, Data> * @return Collection<int, Data>
*/ */
public function cast(DataProperty $property, mixed $value, array $context): mixed public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed
{ {
return collect($value)->map(fn ($item) => $this->target::from($item)); return collect($value)->map(fn ($item) => $this->target::from($item));
} }

View File

@ -5,6 +5,7 @@ namespace App\Form\Casts;
use App\Form\Data\FieldCollection; use App\Form\Data\FieldCollection;
use App\Form\Fields\Field; use App\Form\Fields\Field;
use Spatie\LaravelData\Casts\Cast; use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty; use Spatie\LaravelData\Support\DataProperty;
class FieldCollectionCast implements Cast class FieldCollectionCast implements Cast
@ -14,7 +15,7 @@ class FieldCollectionCast implements Cast
* @param array<string, mixed> $context * @param array<string, mixed> $context
* @return FieldCollection * @return FieldCollection
*/ */
public function cast(DataProperty $property, mixed $value, array $context): mixed public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed
{ {
return new FieldCollection(collect($value)->map(fn ($value) => Field::classFromType($value['type'])::from($value))->all()); return new FieldCollection(collect($value)->map(fn ($value) => Field::classFromType($value['type'])::from($value))->all());
} }

View File

@ -48,7 +48,7 @@ enum NamiType: string
static::LOCATION => $member->location, static::LOCATION => $member->location,
static::NICKNAME => $member->nickname, static::NICKNAME => $member->nickname,
static::GENDER => $member->gender?->name, static::GENDER => $member->gender?->name,
static::AGE => $member->birthday->diffInYears(now()), static::AGE => intVal($member->birthday->diffInYears(now())),
static::AGEEVENT => $member->birthday->diffInYears($form->from), static::AGEEVENT => $member->birthday->diffInYears($form->from),
static::MOBILEPHONE => $member->mobile_phone, static::MOBILEPHONE => $member->mobile_phone,
}; };

View File

@ -5,6 +5,7 @@ namespace App\Form\Transformers;
use App\Form\Fields\Field; use App\Form\Fields\Field;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Spatie\LaravelData\Support\DataProperty; use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer; use Spatie\LaravelData\Transformers\Transformer;
class CollectionTransformer implements Transformer class CollectionTransformer implements Transformer
@ -18,7 +19,7 @@ class CollectionTransformer implements Transformer
* @param Collection<int, Field> $value * @param Collection<int, Field> $value
* @return array<string, mixed> * @return array<string, mixed>
*/ */
public function transform(DataProperty $property, mixed $value): mixed public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed
{ {
return $value->toArray(); return $value->toArray();
} }

View File

@ -5,6 +5,7 @@ namespace App\Form\Transformers;
use App\Form\Fields\Field; use App\Form\Fields\Field;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Spatie\LaravelData\Support\DataProperty; use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer; use Spatie\LaravelData\Transformers\Transformer;
class FieldCollectionTransformer implements Transformer class FieldCollectionTransformer implements Transformer
@ -14,7 +15,7 @@ class FieldCollectionTransformer implements Transformer
* @param Collection<int, Field> $value * @param Collection<int, Field> $value
* @return array<string, mixed> * @return array<string, mixed>
*/ */
public function transform(DataProperty $property, mixed $value): mixed public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed
{ {
return $value->map(fn ($field) => [ return $value->map(fn ($field) => [
...$field->toArray(), ...$field->toArray(),

View File

@ -36,7 +36,7 @@ abstract class InvoiceDocument extends Document
public static function fromInvoice(Invoice $invoice): self public static function fromInvoice(Invoice $invoice): self
{ {
return static::withoutMagicalCreationFrom([ return static::factory()->withoutMagicalCreation()->from([
'toName' => $invoice->to['name'], 'toName' => $invoice->to['name'],
'toAddress' => $invoice->to['address'], 'toAddress' => $invoice->to['address'],
'toZip' => $invoice->to['zip'], 'toZip' => $invoice->to['zip'],

View File

@ -20,12 +20,12 @@ class Condition extends Data
public static function fromMedia(Media $media): self public static function fromMedia(Media $media): self
{ {
return $media->getCustomProperty('conditions') ? static::withoutMagicalCreationFrom($media->getCustomProperty('conditions')) : static::defaults(); return $media->getCustomProperty('conditions') ? static::factory()->withoutMagicalCreation()->from($media->getCustomProperty('conditions')) : static::defaults();
} }
public static function defaults(): self public static function defaults(): self
{ {
return static::withoutMagicalCreationFrom(['mode' => 'any', 'ifs' => []]); return static::factory()->withoutMagicalCreation()->from(['mode' => 'any', 'ifs' => []]);
} }
public function hasStatements(): bool public function hasStatements(): bool

View File

@ -20,7 +20,7 @@ abstract class ConditionResolver
*/ */
public function filterBlock(array $block): bool public function filterBlock(array $block): bool
{ {
return $this->filterCondition(Condition::withoutMagicalCreationFrom([ return $this->filterCondition(Condition::factory()->withoutMagicalCreation()->from([
'mode' => data_get($block, 'tunes.condition.mode', 'any'), 'mode' => data_get($block, 'tunes.condition.mode', 'any'),
'ifs' => data_get($block, 'tunes.condition.ifs', []), 'ifs' => data_get($block, 'tunes.condition.ifs', []),
])); ]));

View File

@ -36,7 +36,7 @@ abstract class Filter extends Data
*/ */
public static function fromPost(?array $post = null): static public static function fromPost(?array $post = null): static
{ {
return static::withoutMagicalCreationFrom($post ?: [])->toDefault(); return static::factory()->withoutMagicalCreation()->from($post ?: [])->toDefault();
} }
/** /**

View File

@ -36,6 +36,6 @@ abstract class ScoutFilter extends Data
*/ */
public static function fromPost(?array $post = null): static public static function fromPost(?array $post = null): static
{ {
return static::withoutMagicalCreationFrom($post ?: []); return static::factory()->withoutMagicalCreation()->from($post ?: []);
} }
} }

View File

@ -26,7 +26,7 @@ class MailingList extends Data
) { ) {
} }
public static function factory(): MailinglistFactory public static function toFactory(): MailinglistFactory
{ {
return MailinglistFactory::new(); return MailinglistFactory::new();
} }

View File

@ -21,7 +21,6 @@ class AppServiceProvider extends ServiceProvider
public function register() public function register()
{ {
JsonResource::withoutWrapping(); JsonResource::withoutWrapping();
Telescope::ignoreMigrations();
\Inertia::share('search', request()->query('search', '')); \Inertia::share('search', request()->query('search', ''));

View File

@ -47,29 +47,28 @@
"require": { "require": {
"php": "^8.3", "php": "^8.3",
"barryvdh/laravel-debugbar": "^3.9", "barryvdh/laravel-debugbar": "^3.9",
"beyondcode/laravel-dump-server": "^1.8", "cviebrock/eloquent-sluggable": "^11.0",
"cviebrock/eloquent-sluggable": "^10.0",
"doctrine/dbal": "^3.1", "doctrine/dbal": "^3.1",
"guzzlehttp/guzzle": "^7.0.1", "guzzlehttp/guzzle": "^7.0.1",
"inertiajs/inertia-laravel": "^0.6.9", "inertiajs/inertia-laravel": "^1.0",
"laravel/framework": "^10.0", "laravel/framework": "^11.0",
"laravel/horizon": "^5.0", "laravel/horizon": "^5.0",
"laravel/passport": "^11.8", "laravel/passport": "^12.8",
"laravel/scout": "^9.8", "laravel/scout": "^10.8",
"laravel/telescope": "^4.13", "laravel/telescope": "^5.0",
"laravel/tinker": "^2.0", "laravel/tinker": "^2.0",
"laravel/ui": "^4.0", "laravel/ui": "^4.0",
"league/csv": "^9.9", "league/csv": "^9.9",
"lorisleiva/laravel-actions": "^2.4", "lorisleiva/laravel-actions": "^2.4",
"meilisearch/meilisearch-php": "^1.6", "meilisearch/meilisearch-php": "^1.6",
"monicahq/laravel-sabre": "^1.6", "monicahq/laravel-sabre": "^1.6",
"nunomaduro/collision": "^7.0", "nunomaduro/collision": "^8.1",
"phake/phake": "^4.2", "phake/phake": "^4.2",
"pusher/pusher-php-server": "^7.2", "pusher/pusher-php-server": "^7.2",
"spatie/laravel-data": "^3.0", "spatie/laravel-data": "^4.0",
"spatie/laravel-ignition": "^2.0", "spatie/laravel-ignition": "^2.0",
"spatie/laravel-settings": "^2.2", "spatie/laravel-settings": "^3.0",
"worksome/request-factories": "^2.5", "worksome/request-factories": "^3.0",
"zoomyboy/laravel-nami": "dev-master", "zoomyboy/laravel-nami": "dev-master",
"zoomyboy/medialibrary-helper": "dev-master as 1.0", "zoomyboy/medialibrary-helper": "dev-master as 1.0",
"league/flysystem-webdav": "dev-master as 3.28.0", "league/flysystem-webdav": "dev-master as 3.28.0",
@ -80,12 +79,12 @@
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.9.1", "fakerphp/faker": "^1.9.1",
"larastan/larastan": "^2.0",
"laravel/envoy": "^2.8", "laravel/envoy": "^2.8",
"mockery/mockery": "^1.4.4", "mockery/mockery": "^1.4.4",
"larastan/larastan": "^2.0", "orchestra/testbench": "^9.0",
"orchestra/testbench": "^8.0", "pestphp/pest": "^3.0",
"phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-mockery": "^1.1"
"phpunit/phpunit": "^10.0"
}, },
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,

2008
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('settings', function (Blueprint $table): void {
$table->boolean('locked')->default(false)->change();
$table->unique(['group', 'name']);
$table->dropIndex(['group']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('settings', function (Blueprint $table): void {
$table->boolean('locked')->default(null)->change();
$table->dropUnique(['group', 'name']);
$table->index('group');
});
}
};

@ -1 +1 @@
Subproject commit de5d8173ea9c7326071512e1094a09f7f3822e91 Subproject commit b735186c2d4f844f67992f86f460d6c3deaf5f28

@ -1 +1 @@
Subproject commit 6d8e9de3d72ce1e117999564a46eda51fbb85b54 Subproject commit 77cfe9bbc7a11ee6494b205458ac5c75ff5c166d

@ -1 +1 @@
Subproject commit 82d52774c65bf527233c637f5f7969de2d31099c Subproject commit 7304963370ff64fb5accf08da4864981cc424301

View File

@ -13,6 +13,7 @@ use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Passport\Client; use Laravel\Passport\Client;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\RequestFactories\ContributionMemberApiRequestFactory; use Tests\RequestFactories\ContributionMemberApiRequestFactory;
use Tests\RequestFactories\ContributionRequestFactory; use Tests\RequestFactories\ContributionRequestFactory;
use Tests\TestCase; use Tests\TestCase;
@ -112,8 +113,8 @@ class StoreTest extends TestCase
/** /**
* @param array<string, string> $input * @param array<string, string> $input
* @param class-string<ContributionDocument> $documentClass * @param class-string<ContributionDocument> $documentClass
* @dataProvider validationDataProvider
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(array $input, string $documentClass, string $errorField): void public function testItValidatesInput(array $input, string $documentClass, string $errorField): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();
@ -127,8 +128,8 @@ class StoreTest extends TestCase
/** /**
* @param array<string, string> $input * @param array<string, string> $input
* @param class-string<ContributionDocument> $documentClass * @param class-string<ContributionDocument> $documentClass
* @dataProvider validationDataProvider
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInputBeforeGeneration(array $input, string $documentClass, string $errorField): void public function testItValidatesInputBeforeGeneration(array $input, string $documentClass, string $errorField): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();
@ -140,7 +141,7 @@ class StoreTest extends TestCase
])->assertSessionHasErrors($errorField); ])->assertSessionHasErrors($errorField);
} }
protected function validationDataProvider(): Generator protected static function validationDataProvider(): Generator
{ {
yield [ yield [
['type' => 'aaa'], ['type' => 'aaa'],

View File

@ -5,6 +5,7 @@ namespace Tests\Feature\Course;
use App\Course\Models\Course; use App\Course\Models\Course;
use App\Member\Member; use App\Member\Member;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
use Zoomyboy\LaravelNami\Fakes\CourseFake; use Zoomyboy\LaravelNami\Fakes\CourseFake;
@ -15,7 +16,7 @@ class StoreTest extends TestCase
/** /**
* @return array<string, array{payload: array<string, mixed>, errors: array<string, mixed>}> * @return array<string, array{payload: array<string, mixed>, errors: array<string, mixed>}>
*/ */
public function validationDataProvider(): array public static function validationDataProvider(): array
{ {
return [ return [
'course_id_missing' => [ 'course_id_missing' => [
@ -48,8 +49,8 @@ class StoreTest extends TestCase
/** /**
* @param array<string, string> $payload * @param array<string, string> $payload
* @param array<string, string> $errors * @param array<string, string> $errors
* @dataProvider validationDataProvider
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(array $payload, array $errors): void public function testItValidatesInput(array $payload, array $errors): void
{ {
$this->login()->withNamiSettings(); $this->login()->withNamiSettings();

View File

@ -6,6 +6,7 @@ use App\Course\Models\Course;
use App\Course\Models\CourseMember; use App\Course\Models\CourseMember;
use App\Member\Member; use App\Member\Member;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
use Zoomyboy\LaravelNami\Fakes\CourseFake; use Zoomyboy\LaravelNami\Fakes\CourseFake;
@ -16,7 +17,7 @@ class UpdateTest extends TestCase
/** /**
* @return array<string, array{payload: array<string, mixed>, errors: array<string, mixed>}> * @return array<string, array{payload: array<string, mixed>, errors: array<string, mixed>}>
*/ */
public function validationDataProvider(): array public static function validationDataProvider(): array
{ {
return [ return [
'course_id_missing' => [ 'course_id_missing' => [
@ -49,8 +50,8 @@ class UpdateTest extends TestCase
/** /**
* @param array<string, string> $payload * @param array<string, string> $payload
* @param array<string, string> $errors * @param array<string, string> $errors
* @dataProvider validationDataProvider
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(array $payload, array $errors): void public function testItValidatesInput(array $payload, array $errors): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();

View File

@ -17,6 +17,7 @@ use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Illuminate\Testing\TestResponse; use Illuminate\Testing\TestResponse;
use PHPUnit\Framework\Attributes\DataProvider;
class FormRegisterActionTest extends FormTestCase class FormRegisterActionTest extends FormTestCase
{ {
@ -86,10 +87,10 @@ class FormRegisterActionTest extends FormTestCase
} }
/** /**
* @dataProvider validationDataProvider
* @param array<string, mixed> $payload * @param array<string, mixed> $payload
* @param ?array<string, mixed> $messages * @param ?array<string, mixed> $messages
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(FormtemplateFieldRequest $fieldGenerator, array $payload, ?array $messages): void public function testItValidatesInput(FormtemplateFieldRequest $fieldGenerator, array $payload, ?array $messages): void
{ {
Carbon::setTestNow(Carbon::parse('2024-02-15 06:00:00')); Carbon::setTestNow(Carbon::parse('2024-02-15 06:00:00'));
@ -105,226 +106,226 @@ class FormRegisterActionTest extends FormTestCase
} }
} }
public function validationDataProvider(): Generator public static function validationDataProvider(): Generator
{ {
yield [ yield [
$this->dateField('birthday')->name('Geburtsdatum')->maxToday(false), static::dateField('birthday')->name('Geburtsdatum')->maxToday(false),
['birthday' => 'aa'], ['birthday' => 'aa'],
['birthday' => 'Geburtsdatum muss ein gültiges Datum sein.'] ['birthday' => 'Geburtsdatum muss ein gültiges Datum sein.']
]; ];
yield [ yield [
$this->dateField('birthday')->name('Geburtsdatum')->maxToday(false), static::dateField('birthday')->name('Geburtsdatum')->maxToday(false),
['birthday' => '2021-05-06'], ['birthday' => '2021-05-06'],
null, null,
]; ];
yield [ yield [
$this->dateField('birthday')->name('Geburtsdatum')->maxToday(true), static::dateField('birthday')->name('Geburtsdatum')->maxToday(true),
['birthday' => '2024-02-16'], ['birthday' => '2024-02-16'],
['birthday' => 'Geburtsdatum muss ein Datum vor oder gleich dem 15.02.2024 sein.'], ['birthday' => 'Geburtsdatum muss ein Datum vor oder gleich dem 15.02.2024 sein.'],
]; ];
yield [ yield [
$this->dateField('birthday')->name('Geburtsdatum')->maxToday(true), static::dateField('birthday')->name('Geburtsdatum')->maxToday(true),
['birthday' => '2024-02-15'], ['birthday' => '2024-02-15'],
null, null,
]; ];
yield [ yield [
$this->textField('vorname')->name('Vorname der Mutter')->required(true), static::textField('vorname')->name('Vorname der Mutter')->required(true),
['vorname' => ''], ['vorname' => ''],
['vorname' => 'Vorname der Mutter ist erforderlich.'] ['vorname' => 'Vorname der Mutter ist erforderlich.']
]; ];
yield [ yield [
$this->textField('vorname')->name('Vorname der Mutter')->required(true), static::textField('vorname')->name('Vorname der Mutter')->required(true),
['vorname' => 5], ['vorname' => 5],
['vorname' => 'Vorname der Mutter muss ein String sein.'] ['vorname' => 'Vorname der Mutter muss ein String sein.']
]; ];
yield [ yield [
$this->radioField('yes_or_no')->name('Ja oder Nein')->required(true), static::radioField('yes_or_no')->name('Ja oder Nein')->required(true),
['yes_or_no' => null], ['yes_or_no' => null],
['yes_or_no' => 'Ja oder Nein ist erforderlich.'] ['yes_or_no' => 'Ja oder Nein ist erforderlich.']
]; ];
yield [ yield [
$this->radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(false)->allowcustom(false), static::radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(false)->allowcustom(false),
['letter' => 'Z'], ['letter' => 'Z'],
['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.'] ['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.']
]; ];
yield [ yield [
$this->radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false), static::radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false),
['letter' => 'Z'], ['letter' => 'Z'],
['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.'] ['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.']
]; ];
yield [ yield [
$this->radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(true), static::radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(true),
['letter' => 'lalalaa'], ['letter' => 'lalalaa'],
null, null,
]; ];
yield [ yield [
$this->radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false), static::radioField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false),
['letter' => 'A'], ['letter' => 'A'],
null null
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']),
['letter' => ['Z']], ['letter' => ['Z']],
['letter.0' => 'Der gewählte Wert für Buchstabe ist ungültig.'], ['letter.0' => 'Der gewählte Wert für Buchstabe ist ungültig.'],
]; ];
yield [ yield [
$this->dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->allowcustom(true), static::dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->allowcustom(true),
['letter' => 'Z'], ['letter' => 'Z'],
null, null,
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']),
['letter' => 77], ['letter' => 77],
['letter' => 'Buchstabe muss ein Array sein.'], ['letter' => 'Buchstabe muss ein Array sein.'],
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']),
['letter' => ['A']], ['letter' => ['A']],
null, null,
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B']),
['letter' => []], ['letter' => []],
null, null,
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(0)->max(2), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(0)->max(2),
['letter' => ['A', 'B', 'C']], ['letter' => ['A', 'B', 'C']],
['letter' => 'Buchstabe darf maximal 2 Elemente haben.'], ['letter' => 'Buchstabe darf maximal 2 Elemente haben.'],
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(2)->max(0), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(2)->max(0),
['letter' => ['A']], ['letter' => ['A']],
['letter' => 'Buchstabe muss mindestens 2 Elemente haben.'], ['letter' => 'Buchstabe muss mindestens 2 Elemente haben.'],
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(1)->max(0), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(1)->max(0),
['letter' => []], ['letter' => []],
['letter' => 'Buchstabe muss mindestens 1 Elemente haben.'], ['letter' => 'Buchstabe muss mindestens 1 Elemente haben.'],
]; ];
yield [ yield [
$this->checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(0)->max(1), static::checkboxesField('letter')->name('Buchstabe')->options(['A', 'B', 'C', 'D'])->min(0)->max(1),
['letter' => ['A', 'B']], ['letter' => ['A', 'B']],
['letter' => 'Buchstabe darf maximal 1 Elemente haben.'], ['letter' => 'Buchstabe darf maximal 1 Elemente haben.'],
]; ];
yield [ yield [
$this->checkboxField('data')->name('Datenschutz')->required(false), static::checkboxField('data')->name('Datenschutz')->required(false),
['data' => 5], ['data' => 5],
['data' => 'Datenschutz muss ein Wahrheitswert sein.'], ['data' => 'Datenschutz muss ein Wahrheitswert sein.'],
]; ];
yield [ yield [
$this->checkboxField('data')->name('Datenschutz')->required(false), static::checkboxField('data')->name('Datenschutz')->required(false),
['data' => false], ['data' => false],
null null
]; ];
yield [ yield [
$this->checkboxField('data')->name('Datenschutz')->required(true), static::checkboxField('data')->name('Datenschutz')->required(true),
['data' => false], ['data' => false],
['data' => 'Datenschutz muss akzeptiert werden.'], ['data' => 'Datenschutz muss akzeptiert werden.'],
]; ];
yield [ yield [
$this->checkboxField('data')->name('Datenschutz')->required(true), static::checkboxField('data')->name('Datenschutz')->required(true),
['data' => true], ['data' => true],
null, null,
]; ];
yield [ yield [
$this->dropdownField('yes_or_no')->name('Ja oder Nein')->required(true), static::dropdownField('yes_or_no')->name('Ja oder Nein')->required(true),
['yes_or_no' => null], ['yes_or_no' => null],
['yes_or_no' => 'Ja oder Nein ist erforderlich.'] ['yes_or_no' => 'Ja oder Nein ist erforderlich.']
]; ];
yield [ yield [
$this->dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->required(false)->allowcustom(false), static::dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->required(false)->allowcustom(false),
['letter' => 'Z'], ['letter' => 'Z'],
['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.'] ['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.']
]; ];
yield [ yield [
$this->dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false), static::dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false),
['letter' => 'Z'], ['letter' => 'Z'],
['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.'] ['letter' => 'Der gewählte Wert für Buchstabe ist ungültig.']
]; ];
yield [ yield [
$this->dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false), static::dropdownField('letter')->name('Buchstabe')->options(['A', 'B'])->required(true)->allowcustom(false),
['letter' => 'A'], ['letter' => 'A'],
null null
]; ];
yield [ yield [
$this->textareaField('vorname')->name('Vorname der Mutter')->required(true), static::textareaField('vorname')->name('Vorname der Mutter')->required(true),
['vorname' => ''], ['vorname' => ''],
['vorname' => 'Vorname der Mutter ist erforderlich.'] ['vorname' => 'Vorname der Mutter ist erforderlich.']
]; ];
yield [ yield [
$this->textareaField('vorname')->name('Vorname der Mutter')->required(true), static::textareaField('vorname')->name('Vorname der Mutter')->required(true),
['vorname' => 5], ['vorname' => 5],
['vorname' => 'Vorname der Mutter muss ein String sein.'] ['vorname' => 'Vorname der Mutter muss ein String sein.']
]; ];
yield [ yield [
$this->textareaField('vorname')->name('Vorname der Mutter')->required(true), static::textareaField('vorname')->name('Vorname der Mutter')->required(true),
['vorname' => 5], ['vorname' => 5],
['vorname' => 'Vorname der Mutter muss ein String sein.'] ['vorname' => 'Vorname der Mutter muss ein String sein.']
]; ];
yield [ yield [
$this->emailField('email')->name('Mail')->required(true), static::emailField('email')->name('Mail')->required(true),
['email' => 'alaaa'], ['email' => 'alaaa'],
['email' => 'Mail muss eine gültige E-Mail-Adresse sein.'] ['email' => 'Mail muss eine gültige E-Mail-Adresse sein.']
]; ];
yield [ yield [
$this->emailField('email')->name('Mail')->required(false), static::emailField('email')->name('Mail')->required(false),
['email' => 'alaaa'], ['email' => 'alaaa'],
['email' => 'Mail muss eine gültige E-Mail-Adresse sein.'] ['email' => 'Mail muss eine gültige E-Mail-Adresse sein.']
]; ];
yield [ yield [
$this->numberField('numb')->name('Nummer')->required(false)->min(10)->max(20), static::numberField('numb')->name('Nummer')->required(false)->min(10)->max(20),
['numb' => 21], ['numb' => 21],
['numb' => 'Nummer muss kleiner oder gleich 20 sein.'] ['numb' => 'Nummer muss kleiner oder gleich 20 sein.']
]; ];
yield [ yield [
$this->numberField('numb')->name('Nummer')->required(false)->min(10)->max(20), static::numberField('numb')->name('Nummer')->required(false)->min(10)->max(20),
['numb' => 9], ['numb' => 9],
['numb' => 'Nummer muss größer oder gleich 10 sein.'] ['numb' => 'Nummer muss größer oder gleich 10 sein.']
]; ];
yield [ yield [
$this->numberField('numb')->name('Nummer')->required(false)->min(10)->max(20), static::numberField('numb')->name('Nummer')->required(false)->min(10)->max(20),
['numb' => 'asss'], ['numb' => 'asss'],
['numb' => 'Nummer muss eine ganze Zahl sein.'] ['numb' => 'Nummer muss eine ganze Zahl sein.']
]; ];
yield [ yield [
$this->numberField('numb')->name('Nummer')->required(true), static::numberField('numb')->name('Nummer')->required(true),
['numb' => ''], ['numb' => ''],
['numb' => 'Nummer ist erforderlich.'] ['numb' => 'Nummer ist erforderlich.']
]; ];
@ -456,7 +457,7 @@ class FormRegisterActionTest extends FormTestCase
$this->assertEquals($form->participants->get(0)->id, $form->participants->get(1)->parent_id); $this->assertEquals($form->participants->get(0)->id, $form->participants->get(1)->parent_id);
} }
protected function memberMatchingDataProvider(): Generator public static function memberMatchingDataProvider(): Generator
{ {
yield [ yield [
['email' => 'max@muster.de'], ['email' => 'max@muster.de'],
@ -539,10 +540,10 @@ class FormRegisterActionTest extends FormTestCase
} }
/** /**
* @dataProvider memberMatchingDataProvider
* @param array<string, string> $memberAttributes * @param array<string, string> $memberAttributes
* @param mixed $participantValue * @param mixed $participantValue
*/ */
#[DataProvider('memberMatchingDataProvider')]
public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue, ?callable $factory = null): void public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue, ?callable $factory = null): void
{ {
Carbon::setTestNow(Carbon::parse('2023-05-04')); Carbon::setTestNow(Carbon::parse('2023-05-04'));

View File

@ -8,6 +8,7 @@ use App\Form\Models\Form;
use App\Form\Models\Participant; use App\Form\Models\Participant;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\RequestFactories\EditorRequestFactory; use Tests\RequestFactories\EditorRequestFactory;
class FormRegisterMailTest extends FormTestCase class FormRegisterMailTest extends FormTestCase
@ -77,25 +78,25 @@ class FormRegisterMailTest extends FormTestCase
$mail->assertHasAttachedData('content2', 'beispiel2.pdf', ['mime' => 'application/pdf']); $mail->assertHasAttachedData('content2', 'beispiel2.pdf', ['mime' => 'application/pdf']);
} }
public function blockDataProvider(): Generator public static function blockDataProvider(): Generator
{ {
yield [ yield [
['mode' => 'all', 'ifs' => []], ['mode' => 'all', 'ifs' => []],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
yield [ yield [
['mode' => 'any', 'ifs' => []], ['mode' => 'any', 'ifs' => []],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
yield [ yield [
['mode' => 'any', 'ifs' => []], ['mode' => 'any', 'ifs' => []],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
@ -104,7 +105,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'any', 'ifs' => [ ['mode' => 'any', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A'] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
@ -113,7 +114,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'any', 'ifs' => [ ['mode' => 'any', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
false, false,
]; ];
@ -123,7 +124,7 @@ class FormRegisterMailTest extends FormTestCase
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'], ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'],
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A'] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
@ -133,7 +134,7 @@ class FormRegisterMailTest extends FormTestCase
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'], ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'],
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A'] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'B'], ['fieldkey' => 'B'],
true, true,
]; ];
@ -143,7 +144,7 @@ class FormRegisterMailTest extends FormTestCase
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'], ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'],
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A'] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'A']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'B'], ['fieldkey' => 'B'],
false, false,
]; ];
@ -152,7 +153,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B'] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => 'B']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'B'], ['fieldkey' => 'B'],
true, true,
]; ];
@ -161,7 +162,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isNotEqual', 'value' => 'A'] ['field' => 'fieldkey', 'comparator' => 'isNotEqual', 'value' => 'A']
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'B'], ['fieldkey' => 'B'],
true, true,
]; ];
@ -170,7 +171,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isIn', 'value' => ['A']] ['field' => 'fieldkey', 'comparator' => 'isIn', 'value' => ['A']]
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
@ -179,7 +180,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isNotIn', 'value' => ['B']] ['field' => 'fieldkey', 'comparator' => 'isNotIn', 'value' => ['B']]
]], ]],
$this->dropdownField('fieldkey')->options(['A', 'B']), static::dropdownField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
@ -188,7 +189,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isNotIn', 'value' => ['B']] ['field' => 'fieldkey', 'comparator' => 'isNotIn', 'value' => ['B']]
]], ]],
$this->radioField('fieldkey')->options(['A', 'B']), static::radioField('fieldkey')->options(['A', 'B']),
['fieldkey' => 'A'], ['fieldkey' => 'A'],
true, true,
]; ];
@ -197,7 +198,7 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => true] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => true]
]], ]],
$this->checkboxField('fieldkey'), static::checkboxField('fieldkey'),
['fieldkey' => true], ['fieldkey' => true],
true, true,
]; ];
@ -206,17 +207,17 @@ class FormRegisterMailTest extends FormTestCase
['mode' => 'all', 'ifs' => [ ['mode' => 'all', 'ifs' => [
['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => false] ['field' => 'fieldkey', 'comparator' => 'isEqual', 'value' => false]
]], ]],
$this->checkboxField('fieldkey'), static::checkboxField('fieldkey'),
['fieldkey' => true], ['fieldkey' => true],
false, false,
]; ];
} }
/** /**
* @dataProvider blockDataProvider
* @param array<string, mixed> $conditions * @param array<string, mixed> $conditions
* @param array<string, mixed> $participantValues * @param array<string, mixed> $participantValues
*/ */
#[DataProvider('blockDataProvider')]
public function testItFiltersForBlockConditions(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void public function testItFiltersForBlockConditions(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void
{ {
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();
@ -242,10 +243,10 @@ class FormRegisterMailTest extends FormTestCase
} }
/** /**
* @dataProvider blockDataProvider
* @param array<string, mixed> $conditions * @param array<string, mixed> $conditions
* @param array<string, mixed> $participantValues * @param array<string, mixed> $participantValues
*/ */
#[DataProvider('blockDataProvider')]
public function testItFiltersForAttachments(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void public function testItFiltersForAttachments(array $conditions, FormtemplateFieldRequest $field, array $participantValues, bool $result): void
{ {
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();

View File

@ -10,6 +10,7 @@ use App\Lib\Events\Succeeded;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Generator; use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\RequestFactories\EditorRequestFactory; use Tests\RequestFactories\EditorRequestFactory;
class FormStoreActionTest extends FormTestCase class FormStoreActionTest extends FormTestCase
@ -80,7 +81,7 @@ class FormStoreActionTest extends FormTestCase
$this->assertEquals(2, $form->export->root->connectionId); $this->assertEquals(2, $form->export->root->connectionId);
} }
public function validationDataProvider(): Generator public static function validationDataProvider(): Generator
{ {
yield [FormRequest::new()->name(''), ['name' => 'Name ist erforderlich.']]; yield [FormRequest::new()->name(''), ['name' => 'Name ist erforderlich.']];
yield [FormRequest::new()->excerpt(''), ['excerpt' => 'Auszug ist erforderlich.']]; yield [FormRequest::new()->excerpt(''), ['excerpt' => 'Auszug ist erforderlich.']];
@ -92,9 +93,9 @@ class FormStoreActionTest extends FormTestCase
/** /**
* @dataProvider validationDataProvider
* @param array<string, string> $messages * @param array<string, string> $messages
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesRequests(FormRequest $request, array $messages): void public function testItValidatesRequests(FormRequest $request, array $messages): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();

View File

@ -10,6 +10,7 @@ use App\Lib\Events\Succeeded;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Generator; use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\RequestFactories\EditorRequestFactory; use Tests\RequestFactories\EditorRequestFactory;
class FormtemplateStoreActionTest extends FormTestCase class FormtemplateStoreActionTest extends FormTestCase
@ -51,12 +52,12 @@ class FormtemplateStoreActionTest extends FormTestCase
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage gespeichert.'); Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage gespeichert.');
} }
public function validationDataProvider(): Generator public static function validationDataProvider(): Generator
{ {
yield [FormtemplateRequest::new()->name(''), ['name' => 'Name ist erforderlich.']]; yield [FormtemplateRequest::new()->name(''), ['name' => 'Name ist erforderlich.']];
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->name('')]), ['config.sections.0.name' => 'Sektionsname ist erforderlich.']]; yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->name('')]), ['config.sections.0.name' => 'Sektionsname ist erforderlich.']];
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([ yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
$this->textField()->name(''), static::textField()->name(''),
])]), ['config.sections.0.fields.0.name' => 'Feldname ist erforderlich.']]; ])]), ['config.sections.0.fields.0.name' => 'Feldname ist erforderlich.']];
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([ yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
FormtemplateFieldRequest::type('') FormtemplateFieldRequest::type('')
@ -65,20 +66,20 @@ class FormtemplateStoreActionTest extends FormTestCase
FormtemplateFieldRequest::type('aaaaa'), FormtemplateFieldRequest::type('aaaaa'),
])]), ['config.sections.0.fields.0.type' => 'Feldtyp ist ungültig.']]; ])]), ['config.sections.0.fields.0.type' => 'Feldtyp ist ungültig.']];
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([ yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
$this->textField(''), static::textField(''),
])]), ['config.sections.0.fields.0.key' => 'Feldkey ist erforderlich.']]; ])]), ['config.sections.0.fields.0.key' => 'Feldkey ist erforderlich.']];
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([ yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
$this->textField('a b'), static::textField('a b'),
])]), ['config.sections.0.fields.0.key' => 'Feldkey Format ist ungültig.']]; ])]), ['config.sections.0.fields.0.key' => 'Feldkey Format ist ungültig.']];
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([ yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
$this->textField()->required('la') static::textField()->required('la')
])]), ['config.sections.0.fields.0.required' => 'Erforderlich muss ein Wahrheitswert sein.']]; ])]), ['config.sections.0.fields.0.required' => 'Erforderlich muss ein Wahrheitswert sein.']];
} }
/** /**
* @dataProvider validationDataProvider
* @param array<string, string> $messages * @param array<string, string> $messages
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesRequests(FormtemplateRequest $request, array $messages): void public function testItValidatesRequests(FormtemplateRequest $request, array $messages): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();

View File

@ -8,6 +8,7 @@ use App\Setting\NamiSettings;
use App\Subactivity; use App\Subactivity;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
use Zoomyboy\LaravelNami\Fakes\ActivityFake; use Zoomyboy\LaravelNami\Fakes\ActivityFake;
use Zoomyboy\LaravelNami\Fakes\GroupFake; use Zoomyboy\LaravelNami\Fakes\GroupFake;
@ -82,11 +83,10 @@ class InitializeActivitiesTest extends TestCase
} }
/** /**
* @dataProvider activityDataProvider
*
* @param array<string, string|null> $activityCheck * @param array<string, string|null> $activityCheck
* @param array<string, string|null> $subactivityCheck * @param array<string, string|null> $subactivityCheck
*/ */
#[DataProvider('activityDataProvider')]
public function testItInitsOtherFields(callable $activityFake, array $activityCheck, ?array $subactivityCheck = null): void public function testItInitsOtherFields(callable $activityFake, array $activityCheck, ?array $subactivityCheck = null): void
{ {
app(GroupFake::class) app(GroupFake::class)

View File

@ -8,6 +8,7 @@ use App\Invoice\Models\Invoice;
use App\Member\Member; use App\Member\Member;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
class InvoiceStoreActionTest extends TestCase class InvoiceStoreActionTest extends TestCase
@ -106,8 +107,8 @@ class InvoiceStoreActionTest extends TestCase
/** /**
* @param array<string, mixed> $input * @param array<string, mixed> $input
* @param array<string, string> $errors * @param array<string, string> $errors
* @dataProvider validationDataProvider
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(array $input, array $errors): void public function testItValidatesInput(array $input, array $errors): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();

View File

@ -9,6 +9,7 @@ use App\Invoice\Models\InvoicePosition;
use App\Member\Member; use App\Member\Member;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
class InvoiceUpdateActionTest extends TestCase class InvoiceUpdateActionTest extends TestCase
@ -144,8 +145,8 @@ class InvoiceUpdateActionTest extends TestCase
/** /**
* @param array<string, mixed> $input * @param array<string, mixed> $input
* @param array<string, string> $errors * @param array<string, string> $errors
* @dataProvider validationDataProvider
*/ */
#[DataProvider('validationDataProvider')]
public function testItValidatesInput(array $input, array $errors): void public function testItValidatesInput(array $input, array $errors): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();

View File

@ -17,6 +17,7 @@ use App\Prevention\PreventionSettings;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\Lib\CreatesFormFields; use Tests\Lib\CreatesFormFields;
use Tests\RequestFactories\EditorRequestFactory; use Tests\RequestFactories\EditorRequestFactory;
use Tests\TestCase; use Tests\TestCase;
@ -169,8 +170,8 @@ class PreventionTest extends TestCase
/** /**
* @param array<int, Prevention> $preventions * @param array<int, Prevention> $preventions
* @param array<string, mixed> $memberAttributes * @param array<string, mixed> $memberAttributes
* @dataProvider attributes
*/ */
#[DataProvider('attributes')]
public function testItRemembersMember(array $memberAttributes, array $preventions): void public function testItRemembersMember(array $memberAttributes, array $preventions): void
{ {
Mail::fake(); Mail::fake();

View File

@ -17,6 +17,7 @@ use App\Region;
use Carbon\Carbon; use Carbon\Carbon;
use Generator; use Generator;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
class ShowTest extends TestCase class ShowTest extends TestCase
@ -177,9 +178,7 @@ class ShowTest extends TestCase
yield [now()->addDays(2), null, false]; yield [now()->addDays(2), null, false];
} }
/** #[DataProvider('membershipDataProvider')]
* @dataProvider membershipDataProvider
*/
public function testItShowsIfMembershipIsActive(Carbon $from, ?Carbon $to, bool $isActive): void public function testItShowsIfMembershipIsActive(Carbon $from, ?Carbon $to, bool $isActive): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();

View File

@ -8,6 +8,7 @@ use App\Member\Membership;
use Generator; use Generator;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase; use Tests\TestCase;
class IndexTest extends TestCase class IndexTest extends TestCase
@ -52,9 +53,7 @@ class IndexTest extends TestCase
yield [now()->addDays(2), null, false]; yield [now()->addDays(2), null, false];
} }
/** #[DataProvider('membershipDataProvider')]
* @dataProvider membershipDataProvider
*/
public function testItShowsIfMembershipIsActive(Carbon $from, ?Carbon $to, bool $isActive): void public function testItShowsIfMembershipIsActive(Carbon $from, ?Carbon $to, bool $isActive): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();

View File

@ -18,62 +18,62 @@ use Tests\Feature\Form\FormtemplateFieldRequest;
trait CreatesFormFields trait CreatesFormFields
{ {
protected function namiField(?string $key = null): FormtemplateFieldRequest protected static function namiField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(NamiField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(NamiField::class)->key($key ?? static::randomKey());
} }
protected function textField(?string $key = null): FormtemplateFieldRequest protected static function textField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(TextField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(TextField::class)->key($key ?? static::randomKey());
} }
protected function numberField(?string $key = null): FormtemplateFieldRequest protected static function numberField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(NumberField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(NumberField::class)->key($key ?? static::randomKey());
} }
protected function emailField(?string $key = null): FormtemplateFieldRequest protected static function emailField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(EmailField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(EmailField::class)->key($key ?? static::randomKey());
} }
protected function checkboxesField(?string $key = null): FormtemplateFieldRequest protected static function checkboxesField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(CheckboxesField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(CheckboxesField::class)->key($key ?? static::randomKey());
} }
protected function textareaField(?string $key = null): FormtemplateFieldRequest protected static function textareaField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(TextareaField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(TextareaField::class)->key($key ?? static::randomKey());
} }
protected function dropdownField(?string $key = null): FormtemplateFieldRequest protected static function dropdownField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(DropdownField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(DropdownField::class)->key($key ?? static::randomKey());
} }
protected function dateField(?string $key = null): FormtemplateFieldRequest protected static function dateField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(DateField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(DateField::class)->key($key ?? static::randomKey());
} }
protected function radioField(?string $key = null): FormtemplateFieldRequest protected static function radioField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(RadioField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(RadioField::class)->key($key ?? static::randomKey());
} }
protected function checkboxField(?string $key = null): FormtemplateFieldRequest protected static function checkboxField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(CheckboxField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(CheckboxField::class)->key($key ?? static::randomKey());
} }
protected function groupField(?string $key = null): FormtemplateFieldRequest protected static function groupField(?string $key = null): FormtemplateFieldRequest
{ {
return FormtemplateFieldRequest::type(GroupField::class)->key($key ?? $this->randomKey()); return FormtemplateFieldRequest::type(GroupField::class)->key($key ?? static::randomKey());
} }
protected function randomKey(): string protected static function randomKey(): string
{ {
return preg_replace('/[\-0-9]/', '', str()->uuid() . str()->uuid()); return preg_replace('/[\-0-9]/', '', str()->uuid() . str()->uuid());
} }

View File

@ -7,6 +7,7 @@ use App\Mailman\Exceptions\MailmanServiceException;
use App\Mailman\Support\MailmanService; use App\Mailman\Support\MailmanService;
use Generator; use Generator;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\RequestFactories\MailmanListRequestFactory; use Tests\RequestFactories\MailmanListRequestFactory;
use Tests\TestCase; use Tests\TestCase;
@ -23,7 +24,7 @@ class ServiceTest extends TestCase
$this->assertTrue($result); $this->assertTrue($result);
Http::assertSentCount(1); Http::assertSentCount(1);
Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/system/versions' === $request->url() && $request->header('Authorization') === ['Basic '.base64_encode('user:secret')]); Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/system/versions' === $request->url() && $request->header('Authorization') === ['Basic ' . base64_encode('user:secret')]);
} }
public function testItFailsWhenChckingCredentials(): void public function testItFailsWhenChckingCredentials(): void
@ -37,7 +38,7 @@ class ServiceTest extends TestCase
$this->assertFalse($result); $this->assertFalse($result);
Http::assertSentCount(1); Http::assertSentCount(1);
Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/system/versions' === $request->url() && $request->header('Authorization') === ['Basic '.base64_encode('user:secret')]); Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/system/versions' === $request->url() && $request->header('Authorization') === ['Basic ' . base64_encode('user:secret')]);
} }
public function testItGetsMembersFromList(): void public function testItGetsMembersFromList(): void
@ -56,7 +57,7 @@ class ServiceTest extends TestCase
$this->assertEquals(994, $result->memberId); $this->assertEquals(994, $result->memberId);
$this->assertEquals('test@example.com', $result->email); $this->assertEquals('test@example.com', $result->email);
Http::assertSentCount(1); Http::assertSentCount(1);
Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/lists/listid/roster/member?page=1&count=10' === $request->url() && $request->header('Authorization') === ['Basic '.base64_encode('user:secret')]); Http::assertSent(fn ($request) => 'GET' === $request->method() && 'http://mailman.test/api/lists/listid/roster/member?page=1&count=10' === $request->url() && $request->header('Authorization') === ['Basic ' . base64_encode('user:secret')]);
} }
public function testItThrowsExceptionWhenLoginFailed(): void public function testItThrowsExceptionWhenLoginFailed(): void
@ -94,21 +95,19 @@ class ServiceTest extends TestCase
foreach (range(3, 40) as $i) { foreach (range(3, 40) as $i) {
yield [ yield [
collect(range(1, $i)) collect(range(1, $i))
->map(fn ($num) => ['email' => 'test'.$num.'@example.com', 'self_link' => 'https://example.com/994']) ->map(fn ($num) => ['email' => 'test' . $num . '@example.com', 'self_link' => 'https://example.com/994'])
->toArray(), ->toArray(),
]; ];
} }
} }
/** #[DataProvider('listDataProvider')]
* @dataProvider listDataProvider
*/
public function testItReturnsMoreThanOneResult(array $totals): void public function testItReturnsMoreThanOneResult(array $totals): void
{ {
$totals = collect($totals); $totals = collect($totals);
foreach ($totals->chunk(10) as $n => $chunk) { foreach ($totals->chunk(10) as $n => $chunk) {
Http::fake([ Http::fake([
'http://mailman.test/api/lists/listid/roster/member?page='.($n + 1).'&count=10' => Http::response(json_encode([ 'http://mailman.test/api/lists/listid/roster/member?page=' . ($n + 1) . '&count=10' => Http::response(json_encode([
'entries' => $chunk, 'entries' => $chunk,
'total_size' => $totals->count(), 'total_size' => $totals->count(),
]), 200), ]), 200),