Skip to content

Commit 5c08a4e

Browse files
committed
TASK: Union test isNullable and withoutNullable
1 parent 5e4d6ce commit 5c08a4e

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

test/Unit/TypeSystem/Type/UnionType/UnionTypeTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace PackageFactory\ComponentEngine\Test\Unit\TypeSystem\Type\UnionType;
2424

25+
use PackageFactory\ComponentEngine\TypeSystem\Type\NullType\NullType;
2526
use PackageFactory\ComponentEngine\TypeSystem\Type\NumberType\NumberType;
2627
use PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType;
2728
use PackageFactory\ComponentEngine\TypeSystem\Type\UnionType\UnionType;
@@ -118,4 +119,52 @@ public function isReturnsFalseIfGivenTypeIsNotCongruent(): void
118119
$this->assertFalse($unionType->is(NumberType::get()));
119120
$this->assertFalse($unionType->is(StringType::get()));
120121
}
122+
123+
/**
124+
* @test
125+
*/
126+
public function isNullableOnNullableString(): void
127+
{
128+
$unionType = UnionType::of(StringType::get(), NullType::get());
129+
130+
$this->assertInstanceOf(UnionType::class, $unionType);
131+
132+
$this->assertTrue($unionType->isNullable());
133+
134+
$nonNullables = $unionType->withoutNullable();
135+
136+
$this->assertTrue($nonNullables->is(StringType::get()));
137+
}
138+
139+
/**
140+
* @test
141+
*/
142+
public function isNullableWithMultipleItems(): void
143+
{
144+
$unionType = UnionType::of(StringType::get(), NumberType::get(), NullType::get());
145+
146+
$this->assertInstanceOf(UnionType::class, $unionType);
147+
148+
$this->assertTrue($unionType->isNullable());
149+
150+
$nonNullables = $unionType->withoutNullable();
151+
152+
$this->assertTrue($nonNullables->is(UnionType::of(StringType::get(), NumberType::get())));
153+
}
154+
155+
/**
156+
* @test
157+
*/
158+
public function isNullableOnNonNullableUnion(): void
159+
{
160+
$unionType = UnionType::of(StringType::get(), NumberType::get());
161+
162+
$this->assertInstanceOf(UnionType::class, $unionType);
163+
164+
$this->assertFalse($unionType->isNullable());
165+
166+
$nonNullables = $unionType->withoutNullable();
167+
168+
$this->assertTrue($nonNullables->is($unionType));
169+
}
121170
}

0 commit comments

Comments
 (0)