@@ -6,12 +6,50 @@ 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 ('null ' , Type::nullable ('null ' ));
17
+ Assert::same ('NULL ' , Type::nullable ('NULL ' ));
18
+ Assert::exception (
19
+ fn () => Type::nullable ('null ' , nullable: false ),
20
+ Nette \InvalidArgumentException::class,
21
+ 'Type null cannot be not nullable. ' ,
22
+ );
23
+
24
+ Assert::same ('mixed ' , Type::nullable ('mixed ' ));
25
+ Assert::exception (
26
+ fn () => Type::nullable ('mixed ' , nullable: false ),
27
+ Nette \InvalidArgumentException::class,
28
+ 'Type mixed cannot be not nullable. ' ,
29
+ );
30
+
31
+ Assert::same ('int|float|string|null ' , Type::nullable ('int|float|string ' ));
32
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|string ' , nullable: false ));
33
+
34
+ Assert::same ('NULL|int|float|string ' , Type::nullable ('NULL|int|float|string ' ));
35
+ Assert::same ('int|float|string ' , Type::nullable ('NULL|int|float|string ' , nullable: false ));
11
36
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 ));
37
+ Assert::same ('int|float|string|null ' , Type::nullable ('int|float|string|null ' ));
38
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|string|null ' , nullable: false ));
39
+
40
+ Assert::same ('int|float|null|string ' , Type::nullable ('int|float|null|string ' ));
41
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|null|string ' , nullable: false ));
42
+
43
+ Assert::exception (
44
+ fn () => Type::nullable ('Foo&Bar ' ),
45
+ Nette \InvalidArgumentException::class,
46
+ 'Intersection types cannot be nullable. ' ,
47
+ );
48
+ Assert::same ('Foo&Bar ' , Type::nullable ('Foo&Bar ' , nullable: false ));
49
+
50
+
51
+ // Union
52
+ Assert::same ('A|string ' , Type::union (A::class, Type::String));
15
53
16
- Assert:: same ( ' ?A ' , Type:: nullable ( ' ?A ' ));
17
- Assert::same ('A ' , Type::nullable ( ' ?A ' , nullable: false ));
54
+ // Intersection
55
+ Assert::same ('A&string ' , Type::intersection (A::class, Type::String ));
0 commit comments