Fixed: Cast gender to null when keine Angabe
This commit is contained in:
parent
5eef3074d7
commit
603b300fb0
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Casters;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Spatie\LaravelData\Casts\Cast;
|
||||||
|
use Spatie\LaravelData\Casts\Uncastable;
|
||||||
|
use Spatie\LaravelData\Support\DataProperty;
|
||||||
|
|
||||||
|
class GenderCast implements Cast
|
||||||
|
{
|
||||||
|
public function cast(DataProperty $property, mixed $value, array $context): DateTimeInterface|Uncastable|null|int
|
||||||
|
{
|
||||||
|
if (23 === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ use Spatie\LaravelData\Attributes\MapInputName;
|
||||||
use Spatie\LaravelData\Attributes\WithCast;
|
use Spatie\LaravelData\Attributes\WithCast;
|
||||||
use Spatie\LaravelData\Data;
|
use Spatie\LaravelData\Data;
|
||||||
use Zoomyboy\LaravelNami\Casters\CarbonCast;
|
use Zoomyboy\LaravelNami\Casters\CarbonCast;
|
||||||
|
use Zoomyboy\LaravelNami\Casters\GenderCast;
|
||||||
use Zoomyboy\LaravelNami\Casters\StringCast;
|
use Zoomyboy\LaravelNami\Casters\StringCast;
|
||||||
use Zoomyboy\LaravelNami\Tests\Factories\MemberRequestFactory;
|
use Zoomyboy\LaravelNami\Tests\Factories\MemberRequestFactory;
|
||||||
|
|
||||||
|
@ -39,7 +40,8 @@ class Member extends Data
|
||||||
public string $email,
|
public string $email,
|
||||||
|
|
||||||
#[MapInputName('geschlechtId')]
|
#[MapInputName('geschlechtId')]
|
||||||
public int $genderId,
|
#[WithCast(GenderCast::class)]
|
||||||
|
public ?int $genderId,
|
||||||
|
|
||||||
#[MapInputName('konfessionId')]
|
#[MapInputName('konfessionId')]
|
||||||
public ?int $confessionId,
|
public ?int $confessionId,
|
||||||
|
@ -123,7 +125,7 @@ class Member extends Data
|
||||||
'spitzname' => $this->nickname ?: '',
|
'spitzname' => $this->nickname ?: '',
|
||||||
'vorname' => $this->firstname ?: '',
|
'vorname' => $this->firstname ?: '',
|
||||||
'nachname' => $this->lastname ?: '',
|
'nachname' => $this->lastname ?: '',
|
||||||
'geschlechtId' => $this->genderId,
|
'geschlechtId' => $this->genderId ?: 23,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'beitragsartId' => $this->feeId,
|
'beitragsartId' => $this->feeId,
|
||||||
'geburtsDatum' => $this->birthday->format('Y-m-d 00:00:00'),
|
'geburtsDatum' => $this->birthday->format('Y-m-d 00:00:00'),
|
||||||
|
|
|
@ -91,6 +91,7 @@ class FetchMemberTest extends TestCase
|
||||||
'mitgliedsNummer' => null,
|
'mitgliedsNummer' => null,
|
||||||
'beitragsartId' => null,
|
'beitragsartId' => null,
|
||||||
'konfessionId' => null,
|
'konfessionId' => null,
|
||||||
|
'geschlechtId' => 23,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$member = $this->login()->member(1000, 1001);
|
$member = $this->login()->member(1000, 1001);
|
||||||
|
@ -108,6 +109,7 @@ class FetchMemberTest extends TestCase
|
||||||
$this->assertNull($member->memberId);
|
$this->assertNull($member->memberId);
|
||||||
$this->assertNull($member->feeId);
|
$this->assertNull($member->feeId);
|
||||||
$this->assertNull($member->confessionId);
|
$this->assertNull($member->confessionId);
|
||||||
|
$this->assertNull($member->genderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMemberFetchCanFail(): void
|
public function testMemberFetchCanFail(): void
|
||||||
|
|
|
@ -138,4 +138,21 @@ class PutMemberTest extends TestCase
|
||||||
'foreign' => 'fff',
|
'foreign' => 'fff',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGenderCanBeNull(): void
|
||||||
|
{
|
||||||
|
app(MemberFake::class)
|
||||||
|
->updatesSuccessfully(103, 16)
|
||||||
|
->shows(103, 16, [
|
||||||
|
'foreign' => 'fff',
|
||||||
|
'kontoverbindung' => ['a' => 'b'],
|
||||||
|
]);
|
||||||
|
$response = $this->login()->putMember(Member::factory()->inNami(103, 16)->toMember(['genderId' => null]));
|
||||||
|
|
||||||
|
$this->assertEquals(16, $response);
|
||||||
|
|
||||||
|
app(MemberFake::class)->assertUpdated(103, 16, [
|
||||||
|
'geschlechtId' => 23,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue