8
8
use PhpKafka \PhpAvroSchemaGenerator \Parser \ClassParserInterface ;
9
9
use PhpKafka \PhpAvroSchemaGenerator \PhpClass \PhpClassInterface ;
10
10
use PhpKafka \PhpAvroSchemaGenerator \PhpClass \PhpClassPropertyInterface ;
11
+ use PhpKafka \PhpAvroSchemaGenerator \PhpClass \PhpClassPropertyType ;
12
+ use PhpKafka \PhpAvroSchemaGenerator \PhpClass \PhpClassPropertyTypeItem ;
11
13
use PHPUnit \Framework \TestCase ;
12
14
13
15
class PhpClassConverterTest extends TestCase
14
16
{
15
17
public function testConvert (): void
16
18
{
17
19
$ property1 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
18
- $ property1 ->expects (self ::once ())->method ('getPropertyType ' )->willReturn (1 );
20
+ $ property1 ->expects (self ::once ())->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( ' array?? ' , true )) );
19
21
$ property2 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
20
- $ property2 ->expects (self ::exactly ( 2 ))->method ('getPropertyType ' )->willReturn (' string| array|int[]|mixed[] ' );
22
+ $ property2 ->expects (self ::once ( ))->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( ' array?? ' , true )) );
21
23
$ property3 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
22
- $ property3 ->expects (self ::exactly ( 2 ))->method ('getPropertyType ' )->willReturn (' string ' );
24
+ $ property3 ->expects (self ::once ( ))->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( ' array?? ' , true )) );
23
25
$ property4 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
24
- $ property4 ->expects (self ::exactly ( 2 ))->method ('getPropertyType ' )->willReturn (' object|XYZ|UC ' );
26
+ $ property4 ->expects (self ::once ( ))->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( ' array?? ' , true )) );
25
27
$ property5 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
26
- $ property5 ->expects (self ::exactly ( 2 ))->method ('getPropertyType ' )->willReturn (' mixed ' );
28
+ $ property5 ->expects (self ::once ( ))->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( ' array?? ' , true )) );
27
29
$ property6 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
28
- $ property6 ->expects (self ::exactly ( 2 ))->method ('getPropertyType ' )->willReturn ('array|mixed[] ' );
30
+ $ property6 ->expects (self ::once ( ))->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( 'array?? ' , true )) );
29
31
30
32
31
33
$ parser = $ this ->getMockForAbstractClass (ClassParserInterface::class);
@@ -34,25 +36,25 @@ public function testConvert(): void
34
36
$ parser ->expects (self ::once ())->method ('getProperties ' )->willReturn (
35
37
[$ property1 , $ property2 , $ property3 , $ property4 , $ property5 , $ property6 ]
36
38
);
37
- $ parser ->expects (self ::exactly (2 ))->method ('getUsedClasses ' )->willReturn (['XYZ ' => 'a \\b \\ZYX ' ]);
38
- $ parser ->expects (self ::exactly (3 ))->method ('getNamespace ' )->willReturn ('x \\y ' );
39
+ // $parser->expects(self::exactly(2))->method('getUsedClasses')->willReturn(['XYZ' => 'a\\b\\ZYX']);
40
+ // $parser->expects(self::exactly(3))->method('getNamespace')->willReturn('x\\y');
39
41
40
42
$ converter = new PhpClassConverter ($ parser );
41
43
self ::assertInstanceOf (PhpClassInterface::class, $ converter ->convert ('some class stuff ' ));
42
44
}
43
45
44
- public function testConvertWithNoNamesace (): void
46
+ public function testConvertWithNoNamespace (): void
45
47
{
46
48
$ property1 = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
47
- $ property1 ->expects (self ::exactly ( 2 ))->method ('getPropertyType ' )->willReturn ('ABC ' );
49
+ $ property1 ->expects (self ::once ( ))->method ('getPropertyType ' )->willReturn (new PhpClassPropertyType ( new PhpClassPropertyTypeItem ( 'ABC ' )) );
48
50
49
51
50
52
$ parser = $ this ->getMockForAbstractClass (ClassParserInterface::class);
51
53
$ parser ->expects (self ::once ())->method ('setCode ' )->with ('some class stuff ' );
52
54
$ parser ->expects (self ::exactly (2 ))->method ('getClassName ' )->willReturn ('foo ' );
53
55
$ parser ->expects (self ::once ())->method ('getProperties ' )->willReturn ([$ property1 ]);
54
- $ parser ->expects (self ::exactly (1 ))->method ('getUsedClasses ' )->willReturn ([]);
55
- $ parser ->expects (self ::exactly (2 ))->method ('getNamespace ' )->willReturn (null );
56
+ // $parser->expects(self::exactly(1))->method('getUsedClasses')->willReturn([]);
57
+ // $parser->expects(self::exactly(2))->method('getNamespace')->willReturn(null);
56
58
57
59
$ converter = new PhpClassConverter ($ parser );
58
60
self ::assertInstanceOf (PhpClassInterface::class, $ converter ->convert ('some class stuff ' ));
@@ -65,4 +67,4 @@ public function testConvertOfNonClass(): void
65
67
$ converter = new PhpClassConverter ($ parser );
66
68
self ::assertNull ($ converter ->convert ('some class stuff ' ));
67
69
}
68
- }
70
+ }
0 commit comments