|
22 | 22 |
|
23 | 23 | namespace PackageFactory\ComponentEngine\Test\Unit\TypeSystem\Type\UnionType; |
24 | 24 |
|
| 25 | +use PackageFactory\ComponentEngine\TypeSystem\Type\NullType\NullType; |
25 | 26 | use PackageFactory\ComponentEngine\TypeSystem\Type\NumberType\NumberType; |
26 | 27 | use PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType; |
27 | 28 | use PackageFactory\ComponentEngine\TypeSystem\Type\UnionType\UnionType; |
@@ -118,4 +119,52 @@ public function isReturnsFalseIfGivenTypeIsNotCongruent(): void |
118 | 119 | $this->assertFalse($unionType->is(NumberType::get())); |
119 | 120 | $this->assertFalse($unionType->is(StringType::get())); |
120 | 121 | } |
| 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 | + } |
121 | 170 | } |
0 commit comments