|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Functional\Bundle\Extractor; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use ReflectionClass; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
8
|
|
|
use Symfony\Component\Validator\Constraints\Email; |
|
|
|
|
|
|
9
|
|
|
use Symfony\Component\Validator\Constraints\Url; |
|
|
|
|
|
|
10
|
|
|
use Zenstruck\Foundry\Bundle\Extractor\Property; |
|
11
|
|
|
use Zenstruck\Foundry\Test\Factories; |
|
12
|
|
|
|
|
13
|
|
|
class PropertyTest extends KernelTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
use Factories; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Property|object|null |
|
19
|
|
|
*/ |
|
20
|
|
|
private $property; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp(): void |
|
23
|
|
|
{ |
|
24
|
|
|
self::bootKernel(); |
|
25
|
|
|
$em = static::getContainer()->get('doctrine.orm.default_entity_manager'); |
|
26
|
|
|
$this->property = new Property($em); |
|
|
|
|
|
|
27
|
|
|
//$this->property = static::getContainer()->get('Zenstruck\Foundry\Bundle\Extractor\Property'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @TODO add an TestEntity in this bundle to decouple from Project and possibility to test all Cases |
|
32
|
|
|
* |
|
33
|
|
|
* @test |
|
34
|
|
|
*/ |
|
35
|
|
|
public function get_probs_from_entity() |
|
36
|
|
|
{ |
|
37
|
|
|
// @TODO replace User Entity with Fixtures |
|
38
|
|
|
$this->markTestSkipped('replace User Entity with Fixtures'); |
|
39
|
|
|
|
|
40
|
|
|
$ref = new ReflectionClass('App\Entity\User'); |
|
41
|
|
|
$probs = $this->property->getScalarPropertiesFromDoctrineFieldMappings($ref); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$this->assertCount(6, $probs); |
|
44
|
|
|
$this->assertIsArray($probs['roles']); |
|
45
|
|
|
$this->assertEquals('ROLE_USER', $probs['roles'][0]); |
|
46
|
|
|
$this->assertTrue($probs['isVerifiedAccount']); |
|
47
|
|
|
$this->assertEquals(10, \mb_strlen($probs['lastLogin'])); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
*/ |
|
53
|
|
|
public function generate_email() |
|
54
|
|
|
{ |
|
55
|
|
|
$email = $this->property->createScalarProperties('string', [], 'email'); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertStringContainsString('@', $email); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @test |
|
62
|
|
|
*/ |
|
63
|
|
|
public function generate_firstname() |
|
64
|
|
|
{ |
|
65
|
|
|
$firstName = $this->property->createScalarProperties('string', [], 'firstName'); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertIsString($firstName); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @test |
|
72
|
|
|
*/ |
|
73
|
|
|
public function generate_integer() |
|
74
|
|
|
{ |
|
75
|
|
|
$int = $this->property->createScalarProperties('integer', [], 'postalCode'); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertIsInt($int); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @test |
|
82
|
|
|
*/ |
|
83
|
|
|
public function generate_bool() |
|
84
|
|
|
{ |
|
85
|
|
|
$bool = $this->property->createScalarProperties('boolean', [], 'isActive'); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertTrue($bool); |
|
88
|
|
|
$this->assertIsBool($bool); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @test |
|
93
|
|
|
*/ |
|
94
|
|
|
public function generate_float() |
|
95
|
|
|
{ |
|
96
|
|
|
$float = $this->property->createScalarProperties('float', [], 'price'); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertIsFloat($float); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @test |
|
103
|
|
|
*/ |
|
104
|
|
|
public function create_json_property_with_field_name_roles() |
|
105
|
|
|
{ |
|
106
|
|
|
$roleUser = $this->property->createJsonPropertyFromAnnotationOrFieldName([], 'roles'); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertIsArray($roleUser); |
|
109
|
|
|
$this->assertEquals('ROLE_USER', $roleUser[0]); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @test |
|
114
|
|
|
*/ |
|
115
|
|
|
public function create_json_property_with_default() |
|
116
|
|
|
{ |
|
117
|
|
|
$roleUser = $this->property->createJsonPropertyFromAnnotationOrFieldName([], 'foo'); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertIsArray($roleUser); |
|
120
|
|
|
$this->assertEquals('DEFAULT', $roleUser[0]); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @test |
|
125
|
|
|
*/ |
|
126
|
|
|
public function create_string_property_from_annotation_or_field_name_with_field_name() |
|
127
|
|
|
{ |
|
128
|
|
|
$displayName = $this->property->createStringPropertyFromAnnotationOrFieldName([], 'displayName'); |
|
129
|
|
|
|
|
130
|
|
|
$this->assertIsString($displayName); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @test |
|
135
|
|
|
*/ |
|
136
|
|
|
public function create_string_property_from_annotation_or_field_name_with_annotation_email() |
|
137
|
|
|
{ |
|
138
|
|
|
// @TODO investigate here |
|
139
|
|
|
$this->markTestSkipped('Symfony Constraints missing'); |
|
140
|
|
|
|
|
141
|
|
|
$emailConstraint = new Email(); |
|
142
|
|
|
$email = $this->property->createStringPropertyFromAnnotationOrFieldName([$emailConstraint], 'displayName'); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertStringContainsString('@', $email); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @test |
|
149
|
|
|
*/ |
|
150
|
|
|
public function create_string_property_from_annotation_or_field_name_with_annotation_url() |
|
151
|
|
|
{ |
|
152
|
|
|
// @TODO investigate here |
|
153
|
|
|
$this->markTestSkipped('Symfony Constraints missing'); |
|
154
|
|
|
|
|
155
|
|
|
$urlConstraint = new Url(); |
|
156
|
|
|
$url = $this->property->createStringPropertyFromAnnotationOrFieldName([$urlConstraint], 'displayName'); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertStringContainsString('http', $url); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @test |
|
163
|
|
|
*/ |
|
164
|
|
|
public function create_date() |
|
165
|
|
|
{ |
|
166
|
|
|
// reset our properties |
|
167
|
|
|
$this->property->setProperties([]); |
|
168
|
|
|
|
|
169
|
|
|
$this->property->createDateTimeProperty('someNiceDateField'); |
|
170
|
|
|
|
|
171
|
|
|
// assert |
|
172
|
|
|
$props = $this->property->getProperties(); |
|
173
|
|
|
$date = new DateTime($props['someNiceDateField']); |
|
174
|
|
|
$this->assertCount(1, $props); |
|
175
|
|
|
$this->assertEquals(10, \mb_strlen($props['someNiceDateField'])); |
|
176
|
|
|
$this->assertInstanceOf(DateTime::class, $date); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths