|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HelloWordPl\SimpleEntityGeneratorBundle\Tests\Lib; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\ClassManager; |
|
7
|
|
|
use HelloWordPl\SimpleEntityGeneratorBundle\Lib\Items\PropertyManager; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Sławomir Kania <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class Helper |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param string $name |
|
17
|
|
|
* @param string $type |
|
18
|
|
|
* @param string $comment |
|
19
|
|
|
* @param array $constraintsParts |
|
20
|
|
|
* @return PropertyManager |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function prepareProperty($name, $type, $comment = "", array $constraintsParts = []) |
|
23
|
|
|
{ |
|
24
|
|
|
$propertyManager = new PropertyManager(); |
|
25
|
|
|
$propertyManager->setName($name); |
|
26
|
|
|
$propertyManager->setType($type); |
|
27
|
|
|
$propertyManager->setComment($comment); |
|
28
|
|
|
|
|
29
|
|
|
$constraintCollection = new ArrayCollection(); |
|
30
|
|
|
foreach ($constraintsParts as $constraintPart) { |
|
31
|
|
|
$constraintCollection->add($constraintPart); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$propertyManager->setConstraints($constraintCollection); |
|
35
|
|
|
|
|
36
|
|
|
return $propertyManager; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $namespace |
|
41
|
|
|
* @return ClassManager |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function prepareBasicClassManager($namespace = "\AppBundle\Entity\User") |
|
44
|
|
|
{ |
|
45
|
|
|
$classManager = new ClassManager(); |
|
46
|
|
|
$classManager->setNamespace($namespace); |
|
47
|
|
|
$classManager->setComment("User entity for tests"); |
|
48
|
|
|
|
|
49
|
|
|
$propertiesCollection = new ArrayCollection(); |
|
50
|
|
|
$propertiesCollection->add(self::prepareProperty("full_name", "string", "", ["NotBlank()"])); |
|
51
|
|
|
$propertiesCollection->add(self::prepareProperty("email", "string", "", ["Email(message = \"Invalid email!\")"])); |
|
52
|
|
|
$propertiesCollection->add(self::prepareProperty("active", "boolean", "Wether user active", ["Type(type='boolean')", "IsTrue()"])); |
|
53
|
|
|
$propertiesCollection->add(self::prepareProperty("new_posts", "Doctrine\Common\Collections\ArrayCollection<AppBundle\Entity\Post>", "User new posts", ["NotNull()", "Valid()"])); |
|
54
|
|
|
|
|
55
|
|
|
$classManager->setProperties($propertiesCollection); |
|
56
|
|
|
|
|
57
|
|
|
return $classManager; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function getStructureYaml() |
|
64
|
|
|
{ |
|
65
|
|
|
return ' |
|
66
|
|
|
- |
|
67
|
|
|
namespace: \AppBundle\Entity\User |
|
68
|
|
|
extends: \AppBundle\Entity\Base |
|
69
|
|
|
comment: "New User entity" |
|
70
|
|
|
multiline_comment: |
|
71
|
|
|
- \'lorem ipsum\' |
|
72
|
|
|
- \'second row\' |
|
73
|
|
|
- \'@\Doctrine\Common\Annotations\Entity()\' |
|
74
|
|
|
properties: |
|
75
|
|
|
- |
|
76
|
|
|
name: username |
|
77
|
|
|
type: string |
|
78
|
|
|
comment: "Username for login" |
|
79
|
|
|
constraints: |
|
80
|
|
|
- NotBlank(message = "Login can not be empty") |
|
81
|
|
|
- NotNull(message = "Login can not be null") |
|
82
|
|
|
- |
|
83
|
|
|
name: email |
|
84
|
|
|
type: string |
|
85
|
|
|
comment: "User email" |
|
86
|
|
|
multiline_comment: |
|
87
|
|
|
- \'@\Doctrine\Common\Annotations\Column()\' |
|
88
|
|
|
- \'lorem ipsum\' |
|
89
|
|
|
- \'third row\' |
|
90
|
|
|
constraints: |
|
91
|
|
|
- NotBlank() |
|
92
|
|
|
- Email(message = "Invalid email") |
|
93
|
|
|
- |
|
94
|
|
|
name: active |
|
95
|
|
|
type: boolean |
|
96
|
|
|
comment: "Wether user is active or not" |
|
97
|
|
|
constraints: |
|
98
|
|
|
- IsTrue() |
|
99
|
|
|
- |
|
100
|
|
|
name: posts |
|
101
|
|
|
type: Doctrine\Common\Collections\ArrayCollection<AppBundle\Entity\Post> |
|
102
|
|
|
comment: User posts |
|
103
|
|
|
- |
|
104
|
|
|
# default comment |
|
105
|
|
|
name: created_at |
|
106
|
|
|
type: DateTime |
|
107
|
|
|
- |
|
108
|
|
|
# default comment |
|
109
|
|
|
name: updated_at |
|
110
|
|
|
type: DateTime |
|
111
|
|
|
- |
|
112
|
|
|
# default comment |
|
113
|
|
|
name: last_post |
|
114
|
|
|
serialized_name: lastPost |
|
115
|
|
|
type: AppBundle\Entity\Post |
|
116
|
|
|
optional: true |
|
117
|
|
|
- |
|
118
|
|
|
namespace: \AppBundle\Entity\Post |
|
119
|
|
|
# no comment |
|
120
|
|
|
properties: |
|
121
|
|
|
- |
|
122
|
|
|
name: content |
|
123
|
|
|
type: string |
|
124
|
|
|
comment: "Post content" |
|
125
|
|
|
constraints: |
|
126
|
|
|
- NotBlank() |
|
127
|
|
|
- |
|
128
|
|
|
# default comment |
|
129
|
|
|
name: created_at |
|
130
|
|
|
type: DateTime |
|
131
|
|
|
- |
|
132
|
|
|
# default comment |
|
133
|
|
|
name: updated_at |
|
134
|
|
|
type: DateTime'; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
|
|
public static function getStructureYamlForTemplateChangeTest() |
|
141
|
|
|
{ |
|
142
|
|
|
return ' |
|
143
|
|
|
- |
|
144
|
|
|
namespace: \AppBundle\Entity\User |
|
145
|
|
|
extends: \AppBundle\Entity\Base |
|
146
|
|
|
comment: "New User entity" |
|
147
|
|
|
configuration: |
|
148
|
|
|
no_interface: false |
|
149
|
|
|
no_phpunit_class: false |
|
150
|
|
|
multiline_comment: |
|
151
|
|
|
- \'lorem ipsum\' |
|
152
|
|
|
- \'second row\' |
|
153
|
|
|
- \'@\Doctrine\Common\Annotations\Entity()\' |
|
154
|
|
|
class_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/ClassTemplate.txt |
|
155
|
|
|
class_constructor_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/ClassConstructorTemplate.txt |
|
156
|
|
|
interface_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/InterfaceTemplate.txt |
|
157
|
|
|
test_class_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/TestClassTemplate.txt |
|
158
|
|
|
properties: |
|
159
|
|
|
- |
|
160
|
|
|
name: id |
|
161
|
|
|
type: integer |
|
162
|
|
|
method_setter_interface_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/MethodSetterInterfaceTemplate.txt |
|
163
|
|
|
method_setter_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/MethodSetterTemplate.txt |
|
164
|
|
|
property_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/PropertyTemplate.txt |
|
165
|
|
|
test_class_method_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/TestMethodTemplate.txt |
|
166
|
|
|
method_getter_interface_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/MethodGetterInterfaceTemplate.txt |
|
167
|
|
|
method_getter_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/MethodGetterTemplate.txt |
|
168
|
|
|
- |
|
169
|
|
|
name: username |
|
170
|
|
|
type: string |
|
171
|
|
|
comment: "Username for login" |
|
172
|
|
|
constraints: |
|
173
|
|
|
- NotBlank(message = "Login can not be empty") |
|
174
|
|
|
- NotNull(message = "Login can not be null") |
|
175
|
|
|
- |
|
176
|
|
|
name: posts |
|
177
|
|
|
type: Doctrine\Common\Collections\ArrayCollection<AppBundle\Entity\Post> |
|
178
|
|
|
comment: User posts |
|
179
|
|
|
- |
|
180
|
|
|
name: active |
|
181
|
|
|
type: boolean |
|
182
|
|
|
comment: "Wether user is active or not" |
|
183
|
|
|
constraints: |
|
184
|
|
|
- IsTrue() |
|
185
|
|
|
method_getter_boolean_interface_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/MethodGetterBooleanInterfaceTemplate.txt |
|
186
|
|
|
method_getter_boolean_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/MethodGetterBooleanTemplate.txt |
|
187
|
|
|
method_getter_manager_template_path: HelloWordPlSimpleEntityGeneratorBundle/Resources/templates_for_test/EmptyTemplate.txt'; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public static function getStructureYamlForTestInlineClassConfuration() |
|
191
|
|
|
{ |
|
192
|
|
|
return ' |
|
193
|
|
|
- |
|
194
|
|
|
namespace: \AppBundle\Entity\Post |
|
195
|
|
|
configuration: |
|
196
|
|
|
no_interface: true |
|
197
|
|
|
no_phpunit_class: true |
|
198
|
|
|
properties: |
|
199
|
|
|
- |
|
200
|
|
|
name: id |
|
201
|
|
|
type: integer'; |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|