@@ -52,7 +52,7 @@ public function testGetProperties()
52
52
$ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), $ propertyParser );
53
53
$ parser ->setCode (file_get_contents ($ filePath ));
54
54
$ properties = $ parser ->getProperties ();
55
- self ::assertCount (15 , $ properties );
55
+ self ::assertCount (16 , $ properties );
56
56
57
57
foreach ($ properties as $ property ) {
58
58
self ::assertInstanceOf (PhpClassPropertyInterface::class, $ property );
@@ -84,12 +84,85 @@ public function testClassWithNoParent(): void
84
84
85
85
}
86
86
87
+ public function testClassWithNullableType (): void
88
+ {
89
+ $ propertyParser = new ClassPropertyParser (new DocCommentParser ());
90
+ $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), $ propertyParser );
91
+ $ parser ->setCode ('
92
+ <?php
93
+ class foo {
94
+ public ?string $bla;
95
+ }
96
+ ' );
97
+ $ properties = $ parser ->getProperties ();
98
+ self ::assertEquals (1 , count ($ properties ));
99
+ self ::assertEquals ('null|string ' , $ properties [0 ]->getPropertyType ());
100
+ }
101
+
102
+ public function testClassWithUnionType (): void
103
+ {
104
+ $ propertyParser = new ClassPropertyParser (new DocCommentParser ());
105
+ $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), $ propertyParser );
106
+ $ parser ->setCode ('
107
+ <?php
108
+ class foo {
109
+ public int|string $bla;
110
+ }
111
+ ' );
112
+ $ properties = $ parser ->getProperties ();
113
+ self ::assertEquals (1 , count ($ properties ));
114
+ self ::assertEquals ('int|string ' , $ properties [0 ]->getPropertyType ());
115
+ }
116
+
117
+ public function testClassWithDocUnionType (): void
118
+ {
119
+ $ propertyParser = new ClassPropertyParser (new DocCommentParser ());
120
+ $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), $ propertyParser );
121
+ $ parser ->setCode ('
122
+ <?php
123
+ class foo {
124
+ /**
125
+ * @var int|string
126
+ */
127
+ public $bla;
128
+ }
129
+ ' );
130
+ $ properties = $ parser ->getProperties ();
131
+ self ::assertEquals (1 , count ($ properties ));
132
+ self ::assertEquals ('int|string ' , $ properties [0 ]->getPropertyType ());
133
+ }
134
+
135
+ public function testClassWithAnnotations (): void
136
+ {
137
+ $ propertyParser = new ClassPropertyParser (new DocCommentParser ());
138
+ $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), $ propertyParser );
139
+ $ parser ->setCode ('
140
+ <?php
141
+ class foo {
142
+ /**
143
+ * @avro-type string
144
+ * @avro-default abc def
145
+ * @avro-doc some doc bla bla
146
+ * @var int|string
147
+ */
148
+ public $bla;
149
+ }
150
+ ' );
151
+ $ properties = $ parser ->getProperties ();
152
+ self ::assertEquals (1 , count ($ properties ));
153
+ self ::assertEquals ('string ' , $ properties [0 ]->getPropertyType ());
154
+ self ::assertEquals ('abc def ' , $ properties [0 ]->getPropertyDefault ());
155
+ self ::assertEquals ('some doc bla bla ' , $ properties [0 ]->getPropertyDoc ());
156
+
157
+ }
158
+
87
159
public function testClassWithNoParentFile (): void
88
160
{
89
161
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
90
162
$ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), $ propertyParser );
91
163
$ parser ->setCode ('<?php class foo extends \RuntimeException {private $x;} ' );
92
- self ::assertEquals ([], $ parser ->getProperties ());
93
-
164
+ $ properties = $ parser ->getProperties ();
165
+ self ::assertEquals (1 , count ($ properties ));
166
+ self ::assertEquals ('string ' , $ properties [0 ]->getPropertyType ());
94
167
}
95
168
}
0 commit comments