This commit is contained in:
philipp lang 2023-02-12 22:39:53 +01:00
parent 1359721d67
commit 8c6635ea0b
12 changed files with 23 additions and 51 deletions

View File

@ -11,10 +11,13 @@ use Spatie\LaravelData\Support\DataProperty;
class CarbonCast implements Cast
{
public function __construct(
protected array|string|null $format = null
protected ?string $format = null
) {
}
/**
* @param array<string, mixed> $context
*/
public function cast(DataProperty $property, mixed $value, array $context): DateTimeInterface|Uncastable|null
{
if ($property->type->isNullable && !$value) {

View File

@ -14,6 +14,9 @@ class NullValueCast implements Cast
) {
}
/**
* @param array<string, mixed> $context
*/
public function cast(DataProperty $property, mixed $value, array $context): DateTimeInterface|Uncastable|null|int
{
if ($this->id === $value) {

View File

@ -11,6 +11,9 @@ class StringCast implements Cast
{
}
/**
* @param array<string, mixed> $context
*/
public function cast(DataProperty $property, mixed $value, array $context): ?string
{
if ($property->type->isNullable && !$value) {

View File

@ -135,7 +135,6 @@ class Member extends Data
'wiederverwendenFlag' => $this->keepdata,
'regionId' => $this->regionId ?: 23,
'staatsangehoerigkeitId' => $this->nationalityId,
'zeitschriftenversand' => $this->sendNewspaper,
'emailVertretungsberechtigter' => $this->emailParents,
'ort' => $this->location,
'plz' => $this->zip,

View File

@ -35,6 +35,9 @@ class Membership extends Data
) {
}
/**
* @return array<string, string|int|null>
*/
public function toNami(): array
{
return [

View File

@ -7,9 +7,6 @@ use Zoomyboy\LaravelNami\Data\Course;
class CourseFake extends Fake
{
private array $defaults = [
];
/**
* @param array<int> $ids
*/

View File

@ -86,7 +86,7 @@ class MemberFake extends Fake
}
/**
* @param array<string, string|int|null> $data
* @param array<string, string|int|bool|null> $data
*/
public function updatesSuccessfully(int $groupId, int $memberId, array $data = []): self
{
@ -117,7 +117,7 @@ class MemberFake extends Fake
}
/**
* @param array<string, string|int|null> $body
* @param array<string, string|int|bool|null> $body
*/
public function assertCreated(int $groupId, array $body): void
{
@ -145,7 +145,7 @@ class MemberFake extends Fake
}
/**
* @param array<string, string|int|null> $body
* @param array<string, string|int|bool|null> $body
*/
public function assertUpdated(int $groupId, int $memberId, array $body): void
{

View File

@ -55,26 +55,6 @@ class Group implements Arrayable
return Nami::feesOf($this->id);
}
public function members(): MemberCollection
{
$members = Nami::membersOf($this->id);
return MemberCollection::make(function () use ($members) {
foreach ($members as $member) {
yield $this->member($member['id']);
}
});
return new MemberCollection(Nami::membersOf($this->id)->map(function ($member) {
return $this->member($member['id']);
}));
}
public function member(int $id): Member
{
return Member::fromNami(Nami::member($this->id, $id));
}
public function activities(): Collection
{
return Nami::activities($this->id);

View File

@ -1,17 +0,0 @@
<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Support\LazyCollection;
class MemberCollection extends LazyCollection
{
public static function fromOverview($items)
{
$self = new self($items);
return $self->map(function ($item) {
return Member::fromOverview($item);
});
}
}

View File

@ -2,13 +2,16 @@
namespace Zoomyboy\LaravelNami\Tests\Factories;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Promise\PromiseInterface;
use Illuminate\Support\Facades\Http;
use Worksome\RequestFactories\RequestFactory;
use Zoomyboy\LaravelNami\Data\Member;
class MemberRequestFactory extends RequestFactory
{
/**
* @return array<string, mixed>
*/
public function definition(): array
{
return [
@ -48,7 +51,7 @@ class MemberRequestFactory extends RequestFactory
]);
}
public function toSingleHttp(): FulfilledPromise
public function toSingleHttp(): PromiseInterface
{
return Http::response(json_encode([
'success' => true,

View File

@ -116,6 +116,8 @@ class FetchMemberTest extends TestCase
/**
* @testWith [{"eintrittsdatum": null}]
* [{"landId": null}]
*
* @param array<string, mixed> $data
*/
public function testFailsFetchingWhenJoinedAtDateIsMissing(array $data): void
{

View File

@ -22,8 +22,6 @@ class PutMemberTest extends TestCase
'birthday' => '2021-02-02 00:00:00',
'email' => 'aa@b.de',
'countryId' => 78,
'keepdata' => false,
'sendNewspaper' => false,
'regionId' => 11,
'nationalityId' => 12,
'beitragsartId' => null,
@ -55,8 +53,6 @@ class PutMemberTest extends TestCase
'geburtsDatum' => '2021-02-02 00:00:00',
'konfessionId' => 33,
'landId' => 78,
'wiederverwendenFlag' => false,
'zeitschriftenversand' => false,
'regionId' => 11,
'staatsangehoerigkeitId' => 12,
'ersteTaetigkeitId' => 78,