@@ -6,12 +6,35 @@ use Nette\PhpGenerator\Type;
6
6
use Tester \Assert ;
7
7
require __DIR__ . '/../bootstrap.php ' ;
8
8
9
+ // Nullable
10
+ Assert::same ('?int ' , Type::nullable (Type::Int));
11
+ Assert::same ('int ' , Type::nullable (Type::Int, nullable: false ));
9
12
10
- Assert::same ('A|string ' , Type::union (A::class, Type::String));
13
+ Assert::same ('?int ' , Type::nullable ('?int ' ));
14
+ Assert::same ('int ' , Type::nullable ('?int ' , nullable: false ));
15
+
16
+ Assert::same ('int|float|string|null ' , Type::nullable ('int|float|string ' ));
17
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|string ' , nullable: false ));
18
+
19
+ Assert::same ('NULL|int|float|string ' , Type::nullable ('NULL|int|float|string ' ));
20
+ Assert::same ('int|float|string ' , Type::nullable ('NULL|int|float|string ' , nullable: false ));
21
+
22
+ Assert::same ('int|float|string|null ' , Type::nullable ('int|float|string|null ' ));
23
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|string|null ' , nullable: false ));
11
24
12
- Assert::same ('?A ' , Type::nullable (A::class));
13
- Assert::same ('?A ' , Type::nullable (A::class));
14
- Assert::same ('A ' , Type::nullable (A::class, nullable: false ));
25
+ Assert::same ('int|float|null|string ' , Type::nullable ('int|float|null|string ' ));
26
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|null|string ' , nullable: false ));
27
+
28
+ Assert::exception (
29
+ fn () => Type::nullable ('Foo&Bar ' ),
30
+ Nette \InvalidArgumentException::class,
31
+ 'Intersection types cannot be nullable. ' ,
32
+ );
33
+ Assert::same ('Foo&Bar ' , Type::nullable ('Foo&Bar ' , nullable: false ));
34
+
35
+
36
+ // Union
37
+ Assert::same ('A|string ' , Type::union (A::class, Type::String));
15
38
16
- Assert:: same ( ' ?A ' , Type:: nullable ( ' ?A ' ));
17
- Assert::same ('A ' , Type::nullable ( ' ?A ' , nullable: false ));
39
+ // Intersection
40
+ Assert::same ('A&string ' , Type::intersection (A::class, Type::String ));
0 commit comments