9
9
use PhpKafka \PhpAvroSchemaGenerator \Parser \DocCommentParser ;
10
10
use PhpKafka \PhpAvroSchemaGenerator \PhpClass \PhpClassPropertyInterface ;
11
11
use PhpParser \ParserFactory ;
12
+ use PhpParser \PhpVersion ;
12
13
use PHPUnit \Framework \TestCase ;
13
14
14
15
/**
@@ -20,7 +21,7 @@ public function testGetClassName(): void
20
21
{
21
22
$ filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php ' ;
22
23
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
23
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
24
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
24
25
$ parser ->setCode ((string ) file_get_contents ($ filePath ));
25
26
self ::assertEquals ('SomeTestClass ' , $ parser ->getClassName ());
26
27
self ::assertEquals ('SomeTestClass ' , $ parser ->getClassName ());
@@ -30,7 +31,7 @@ public function testGetClassNameForInterface(): void
30
31
{
31
32
$ filePath = __DIR__ . '/../../../example/classes/SomeTestInterface.php ' ;
32
33
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
33
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
34
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
34
35
$ parser ->setCode ((string ) file_get_contents ($ filePath ));
35
36
self ::assertNull ($ parser ->getClassName ());
36
37
}
@@ -39,7 +40,7 @@ public function testGetNamespace(): void
39
40
{
40
41
$ filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php ' ;
41
42
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
42
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
43
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
43
44
$ parser ->setCode ((string ) file_get_contents ($ filePath ));
44
45
self ::assertEquals ('PhpKafka \\PhpAvroSchemaGenerator \\Example ' , $ parser ->getNamespace ());
45
46
self ::assertEquals ('PhpKafka \\PhpAvroSchemaGenerator \\Example ' , $ parser ->getNamespace ());
@@ -49,7 +50,7 @@ public function testGetProperties(): void
49
50
{
50
51
$ filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php ' ;
51
52
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
52
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
53
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
53
54
$ parser ->setCode ((string ) file_get_contents ($ filePath ));
54
55
$ properties = $ parser ->getProperties ();
55
56
self ::assertCount (16 , $ properties );
@@ -62,7 +63,7 @@ public function testGetProperties(): void
62
63
public function testClassAndNamespaceAreNullWithNoCode (): void
63
64
{
64
65
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
65
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
66
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
66
67
$ refObject = new \ReflectionObject ($ parser );
67
68
$ refProperty = $ refObject ->getProperty ('statements ' );
68
69
$ refProperty ->setAccessible (true );
@@ -76,7 +77,7 @@ public function testClassAndNamespaceAreNullWithNoCode(): void
76
77
public function testClassWithNoParent (): void
77
78
{
78
79
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
79
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
80
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
80
81
$ parser ->setCode ('<?php class foo {} ' );
81
82
self ::assertNull ($ parser ->getNamespace ());
82
83
self ::assertNull ($ parser ->getParentClassName ());
@@ -87,7 +88,7 @@ public function testClassWithNoParent(): void
87
88
public function testClassWithNullableType (): void
88
89
{
89
90
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
90
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
91
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
91
92
$ parser ->setCode ('
92
93
<?php
93
94
class foo {
@@ -102,7 +103,7 @@ class foo {
102
103
public function testClassWithUnionType (): void
103
104
{
104
105
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
105
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
106
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
106
107
$ parser ->setCode ('
107
108
<?php
108
109
class foo {
@@ -117,7 +118,7 @@ class foo {
117
118
public function testClassWithDocUnionType (): void
118
119
{
119
120
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
120
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
121
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
121
122
$ parser ->setCode ('
122
123
<?php
123
124
class foo {
@@ -135,7 +136,7 @@ class foo {
135
136
public function testClassWithAnnotations (): void
136
137
{
137
138
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
138
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
139
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
139
140
$ parser ->setCode ('
140
141
<?php
141
142
class foo {
@@ -159,7 +160,7 @@ class foo {
159
160
public function testClassWithNoParentFile (): void
160
161
{
161
162
$ propertyParser = new ClassPropertyParser (new DocCommentParser ());
162
- $ parser = new ClassParser ((new ParserFactory ())->create (ParserFactory:: PREFER_PHP7 ), $ propertyParser );
163
+ $ parser = new ClassParser ((new ParserFactory ())->createForVersion (PhpVersion:: fromComponents ( 8 , 2 ) ), $ propertyParser );
163
164
$ parser ->setCode ('<?php class foo extends \RuntimeException {private $x;} ' );
164
165
$ properties = $ parser ->getProperties ();
165
166
self ::assertEquals (1 , count ($ properties ));
0 commit comments