@@ -34,4 +34,44 @@ public function testIsNullable()
34
34
35
35
$ this ->assertFalse (Type::int ()->isNullable ());
36
36
}
37
+
38
+ public function testTraverse ()
39
+ {
40
+ $ this ->assertEquals ([Type::int ()], iterator_to_array (Type::int ()->traverse ()));
41
+
42
+ $ this ->assertEquals (
43
+ [Type::union (Type::int (), Type::string ()), Type::int (), Type::string ()],
44
+ iterator_to_array (Type::union (Type::int (), Type::string ())->traverse ()),
45
+ );
46
+ $ this ->assertEquals (
47
+ [Type::union (Type::int (), Type::string ())],
48
+ iterator_to_array (Type::union (Type::int (), Type::string ())->traverse (traverseComposite: false )),
49
+ );
50
+
51
+ $ this ->assertEquals (
52
+ [Type::generic (Type::object (\Traversable::class), Type::string ()), Type::object (\Traversable::class)],
53
+ iterator_to_array (Type::generic (Type::object (\Traversable::class), Type::string ())->traverse ()),
54
+ );
55
+ $ this ->assertEquals (
56
+ [Type::generic (Type::object (\Traversable::class), Type::string ())],
57
+ iterator_to_array (Type::generic (Type::object (\Traversable::class), Type::string ())->traverse (traverseWrapped: false )),
58
+ );
59
+
60
+ $ this ->assertEquals (
61
+ [Type::nullable (Type::int ()), Type::int (), Type::null ()],
62
+ iterator_to_array (Type::nullable (Type::int ())->traverse ()),
63
+ );
64
+ $ this ->assertEquals (
65
+ [Type::nullable (Type::int ()), Type::int ()],
66
+ iterator_to_array (Type::nullable (Type::int ())->traverse (traverseComposite: false )),
67
+ );
68
+ $ this ->assertEquals (
69
+ [Type::nullable (Type::int ()), Type::int (), Type::null ()],
70
+ iterator_to_array (Type::nullable (Type::int ())->traverse (traverseWrapped: false )),
71
+ );
72
+ $ this ->assertEquals (
73
+ [Type::nullable (Type::int ())],
74
+ iterator_to_array (Type::nullable (Type::int ())->traverse (traverseComposite: false , traverseWrapped: false )),
75
+ );
76
+ }
37
77
}
0 commit comments