diff --git a/src/Metadata/Model/TypeMeta.php b/src/Metadata/Model/TypeMeta.php index 98612cb..443c109 100644 --- a/src/Metadata/Model/TypeMeta.php +++ b/src/Metadata/Model/TypeMeta.php @@ -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; @@ -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; } @@ -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(), @@ -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; } @@ -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(), @@ -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(), diff --git a/tests/Unit/Metadata/Collection/TypeMetaTest.php b/tests/Unit/Metadata/Collection/TypeMetaTest.php index 677ef36..5b15095 100644 --- a/tests/Unit/Metadata/Collection/TypeMetaTest.php +++ b/tests/Unit/Metadata/Collection/TypeMetaTest.php @@ -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() @@ -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() @@ -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() @@ -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()