|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GeneratedHydratorTest\CodeGenerator\Visitor; |
|
6
|
|
|
|
|
7
|
|
|
use GeneratedHydrator\CodeGenerator\Visitor\ObjectProperty; |
|
8
|
|
|
use GeneratedHydratorTestAsset\ClassWithTypedProperties; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use ReflectionProperty; |
|
11
|
|
|
|
|
12
|
|
|
/** @covers \GeneratedHydrator\CodeGenerator\Visitor\ObjectProperty */ |
|
13
|
|
|
class ObjectPropertyTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testObjectPropertyState() : void |
|
16
|
|
|
{ |
|
17
|
|
|
$property0 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'property0')); |
|
18
|
|
|
$property1 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'property1')); |
|
19
|
|
|
$property2 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'property2')); |
|
20
|
|
|
$property3 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'property3')); |
|
21
|
|
|
$property4 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'property4')); |
|
22
|
|
|
$untyped0 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'untyped0')); |
|
23
|
|
|
$untyped1 = ObjectProperty::fromReflection(new ReflectionProperty(ClassWithTypedProperties::class, 'untyped1')); |
|
24
|
|
|
|
|
25
|
|
|
self::assertSame('property0', $property0->name); |
|
26
|
|
|
self::assertSame('property1', $property1->name); |
|
27
|
|
|
self::assertSame('property2', $property2->name); |
|
28
|
|
|
self::assertSame('property3', $property3->name); |
|
29
|
|
|
self::assertSame('property4', $property4->name); |
|
30
|
|
|
self::assertSame('untyped0', $untyped0->name); |
|
31
|
|
|
self::assertSame('untyped1', $untyped1->name); |
|
32
|
|
|
|
|
33
|
|
|
self::assertTrue($property0->hasType); |
|
34
|
|
|
self::assertTrue($property1->hasType); |
|
35
|
|
|
self::assertTrue($property2->hasType); |
|
36
|
|
|
self::assertTrue($property3->hasType); |
|
37
|
|
|
self::assertTrue($property4->hasType); |
|
38
|
|
|
self::assertFalse($untyped0->hasType); |
|
39
|
|
|
self::assertFalse($untyped1->hasType); |
|
40
|
|
|
|
|
41
|
|
|
self::assertTrue($property0->hasDefault); |
|
42
|
|
|
self::assertTrue($property1->hasDefault); |
|
43
|
|
|
self::assertFalse($property2->hasDefault); |
|
44
|
|
|
self::assertFalse($property3->hasDefault); |
|
45
|
|
|
self::assertTrue($property4->hasDefault); |
|
46
|
|
|
self::assertTrue($untyped0->hasDefault); |
|
47
|
|
|
self::assertTrue($untyped1->hasDefault); |
|
48
|
|
|
|
|
49
|
|
|
self::assertFalse($property0->allowsNull); |
|
50
|
|
|
self::assertTrue($property1->allowsNull); |
|
51
|
|
|
self::assertFalse($property2->allowsNull); |
|
52
|
|
|
self::assertTrue($property3->allowsNull); |
|
53
|
|
|
self::assertTrue($property4->allowsNull); |
|
54
|
|
|
self::assertTrue($untyped0->allowsNull); |
|
55
|
|
|
self::assertTrue($untyped1->allowsNull); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|