Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Metadata/Model/TypeMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use function Psl\Type\bool;
use function Psl\Type\mixed_dict;
use function Psl\Type\non_empty_string;
use function Psl\Type\nullable;
use function Psl\Type\optional;
use function Psl\Type\shape;
use function Psl\Type\string;
Expand Down Expand Up @@ -235,7 +236,7 @@ public function enums(): Option
public function withEnums(?array $enums): self
{
$new = clone $this;
$new->enums = from_nullable(optional(vec(string()))->coerce($enums));
$new->enums = from_nullable(nullable(vec(string()))->coerce($enums));

return $new;
}
Expand All @@ -254,7 +255,7 @@ public function extends(): Option
public function withExtends(?array $extends): self
{
$new = clone $this;
$new->extends = from_nullable(optional(
$new->extends = from_nullable(nullable(
shape([
'type' => non_empty_string(),
'namespace' => non_empty_string(),
Expand Down Expand Up @@ -487,7 +488,7 @@ public function restriction(): Option
public function withRestriction(?array $restriction): self
{
$new = clone $this;
$new->restriction = from_nullable(optional(mixed_dict())->coerce($restriction));
$new->restriction = from_nullable(nullable(mixed_dict())->coerce($restriction));

return $new;
}
Expand All @@ -506,7 +507,7 @@ public function unions(): Option
public function withUnions(?array $unions): self
{
$new = clone $this;
$new->unions = from_nullable(optional(
$new->unions = from_nullable(nullable(
vec(
shape([
'type' => non_empty_string(),
Expand Down Expand Up @@ -565,7 +566,7 @@ public function arrayType(): Option
public function withArrayType(?array $arrayType): self
{
$new = clone $this;
$new->arrayType = from_nullable(optional(
$new->arrayType = from_nullable(nullable(
shape([
'type' => non_empty_string(),
'itemType' => non_empty_string(),
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/Metadata/Collection/TypeMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function test_it_has_enums()
$value = ['hello', 'world'];
$meta = (new TypeMeta())->withEnums($value);
static::assertSame($value, $meta->enums()->unwrapOr(null));

$emptied = $meta->withEnums(null);
static::assertNotSame($meta, $emptied);
static::assertTrue($emptied->enums()->isNone());
}

public function test_it_has_extends()
Expand All @@ -44,6 +48,10 @@ public function test_it_has_extends()
];
$meta = (new TypeMeta())->withExtends($value);
static::assertSame($value, $meta->extends()->unwrapOr(null));

$emptied = $meta->withExtends(null);
static::assertNotSame($meta, $emptied);
static::assertTrue($emptied->extends()->isNone());
}

public function test_it_has_fixed()
Expand Down Expand Up @@ -135,6 +143,10 @@ public function test_it_has_restriction()
$value = ['mixed' => ['content']];
$meta = (new TypeMeta())->withRestriction($value);
static::assertSame($value, $meta->restriction()->unwrapOr(null));

$emptied = $meta->withRestriction(null);
static::assertNotSame($meta, $emptied);
static::assertTrue($emptied->restriction()->isNone());
}

public function test_it_has_unions()
Expand All @@ -148,6 +160,10 @@ public function test_it_has_unions()
];
$meta = (new TypeMeta())->withUnions($value);
static::assertSame($value, $meta->unions()->unwrapOr(null));

$emptied = $meta->withUnions(null);
static::assertNotSame($meta, $emptied);
static::assertTrue($emptied->unions()->isNone());
}

public function test_it_has_use()
Expand Down
Loading