Skip to content

Commit e8d1ca2

Browse files
authored
Keep annotations in tests (#45)
For the moment, we can't replace annotations by attributes in tests, as `webfactory/doctrine-orm-test-infrastructure` is strongly coupled to `Doctrine\ORM\Mapping\Driver\AnnotationDriver` and `Doctrine\Common\Annotations\AnnotationReader`.
1 parent cb47e0d commit e8d1ca2

8 files changed

+265
-101
lines changed

tests/Functional/CascadePersistTranslationsTest.php

+34-13
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,33 @@ public function adding_and_persisting_translations(): void
4444
}
4545
}
4646

47+
/**
48+
* @ORM\Entity
49+
*/
4750
#[Polyglot\Locale(primary: 'en_GB')]
48-
#[ORM\Entity]
4951
class CascadePersistTranslationsTest_Entity
5052
{
51-
#[ORM\Column(type: 'integer')]
52-
#[ORM\Id]
53-
#[ORM\GeneratedValue]
53+
/**
54+
* @ORM\Column(type="integer")
55+
*
56+
* @ORM\Id
57+
*
58+
* @ORM\GeneratedValue
59+
*/
5460
private ?int $id = null;
5561

5662
/**
5763
* (!) There is *not* cascade="persist" configuration here.
64+
*
65+
* @ORM\OneToMany(targetEntity="CascadePersistTranslationsTest_Translation", mappedBy="entity")
5866
*/
5967
#[Polyglot\TranslationCollection]
60-
#[ORM\OneToMany(targetEntity: \CascadePersistTranslationsTest_Translation::class, mappedBy: 'entity')]
6168
protected Collection $translations;
6269

70+
/**
71+
* @ORM\Column(type="string")
72+
*/
6373
#[Polyglot\Translatable]
64-
#[ORM\Column(type: 'string')]
6574
protected string|TranslatableInterface $text;
6675

6776
public function __construct()
@@ -76,21 +85,33 @@ public function addTranslation(string $locale, mixed $text): void
7685
}
7786
}
7887

79-
#[ORM\Entity]
88+
/**
89+
* @ORM\Entity
90+
*/
8091
class CascadePersistTranslationsTest_Translation
8192
{
82-
#[ORM\Id]
83-
#[ORM\GeneratedValue]
84-
#[ORM\Column(type: 'integer')]
93+
/**
94+
* @ORM\Id
95+
*
96+
* @ORM\GeneratedValue
97+
*
98+
* @ORM\Column(type="integer")
99+
*/
85100
private ?int $id = null;
86101

102+
/**
103+
* @ORM\Column
104+
*/
87105
#[Polyglot\Locale]
88-
#[ORM\Column]
89106
private string $locale;
90107

91-
#[ORM\ManyToOne(targetEntity: \CascadePersistTranslationsTest_Entity::class, inversedBy: 'translations')]
108+
/**
109+
* @ORM\ManyToOne(targetEntity="CascadePersistTranslationsTest_Entity", inversedBy="translations")
110+
*/
92111
private CascadePersistTranslationsTest_Entity $entity;
93112

94-
#[ORM\Column]
113+
/**
114+
* @ORM\Column
115+
*/
95116
private string $text;
96117
}

tests/Functional/EntityInheritanceTest.php

+69-26
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,39 @@ public function testUpdateTranslations(): void
101101
}
102102
}
103103

104+
/**
105+
* @ORM\Entity()
106+
*
107+
* @ORM\InheritanceType(value="SINGLE_TABLE")
108+
*
109+
* @ORM\DiscriminatorMap({"base"="EntityInheritance_BaseEntityClass", "child"="EntityInheritance_ChildEntityClass"})
110+
*
111+
* @ORM\DiscriminatorColumn(name="discriminator", type="string")
112+
*/
104113
#[Polyglot\Locale(primary: 'en_GB')]
105-
#[ORM\Entity]
106-
#[ORM\InheritanceType(value: 'SINGLE_TABLE')]
107-
#[ORM\DiscriminatorMap(['base' => 'EntityInheritance_BaseEntityClass', 'child' => 'EntityInheritance_ChildEntityClass'])]
108-
#[ORM\DiscriminatorColumn(name: 'discriminator', type: 'string')]
109114
class EntityInheritance_BaseEntityClass
110115
{
111-
#[ORM\Column(type: 'integer')]
112-
#[ORM\Id]
113-
#[ORM\GeneratedValue]
116+
/**
117+
* @ORM\Column(type="integer")
118+
*
119+
* @ORM\Id
120+
*
121+
* @ORM\GeneratedValue
122+
*/
114123
private ?int $id = null;
115124

116125
private string $discriminator;
117126

127+
/**
128+
* @ORM\OneToMany(targetEntity="EntityInheritance_BaseEntityClassTranslation", mappedBy="entity")
129+
*/
118130
#[Polyglot\TranslationCollection]
119-
#[ORM\OneToMany(targetEntity: \EntityInheritance_BaseEntityClassTranslation::class, mappedBy: 'entity')]
120131
private Collection $translations;
121132

133+
/**
134+
* @ORM\Column(type="string")
135+
*/
122136
#[Polyglot\Translatable]
123-
#[ORM\Column(type: 'string')]
124137
private TranslatableInterface|string|null $text = null;
125138

126139
public function __construct()
@@ -144,34 +157,52 @@ public function getText(): TranslatableInterface
144157
}
145158
}
146159

147-
#[ORM\Entity]
160+
/**
161+
* @ORM\Entity
162+
*/
148163
class EntityInheritance_BaseEntityClassTranslation
149164
{
150-
#[ORM\Id]
151-
#[ORM\GeneratedValue]
152-
#[ORM\Column(type: 'integer')]
165+
/**
166+
* @ORM\Id
167+
*
168+
* @ORM\GeneratedValue
169+
*
170+
* @ORM\Column(type="integer")
171+
*/
153172
private ?int $id = null;
154173

174+
/**
175+
* @ORM\Column
176+
*/
155177
#[Polyglot\Locale]
156-
#[ORM\Column]
157178
private string $locale;
158179

159-
#[ORM\ManyToOne(targetEntity: \EntityInheritance_BaseEntityClass::class, inversedBy: 'translations')]
180+
/**
181+
* @ORM\ManyToOne(targetEntity="EntityInheritance_BaseEntityClass", inversedBy="translations")
182+
*/
160183
private EntityInheritance_BaseEntityClass $entity;
161184

162-
#[ORM\Column]
185+
/**
186+
* @ORM\Column()
187+
*/
163188
private string $text;
164189
}
165190

166-
#[ORM\Entity]
191+
/**
192+
* @ORM\Entity
193+
*/
167194
class EntityInheritance_ChildEntityClass extends EntityInheritance_BaseEntityClass
168195
{
196+
/**
197+
* @ORM\Column(type="string")
198+
*/
169199
#[Polyglot\Translatable]
170-
#[ORM\Column(type: 'string')]
171200
private TranslatableInterface|string|null $extraText = null;
172201

202+
/**
203+
* @ORM\OneToMany(targetEntity="EntityInheritance_ChildEntityClassTranslation", mappedBy="entity")
204+
*/
173205
#[Polyglot\TranslationCollection]
174-
#[ORM\OneToMany(targetEntity: \EntityInheritance_ChildEntityClassTranslation::class, mappedBy: 'entity')]
175206
private Collection $extraTranslations;
176207

177208
public function __construct()
@@ -191,21 +222,33 @@ public function getExtraText(): TranslatableInterface
191222
}
192223
}
193224

194-
#[ORM\Entity]
225+
/**
226+
* @ORM\Entity
227+
*/
195228
class EntityInheritance_ChildEntityClassTranslation
196229
{
197-
#[ORM\Id]
198-
#[ORM\GeneratedValue]
199-
#[ORM\Column(type: 'integer')]
230+
/**
231+
* @ORM\Id
232+
*
233+
* @ORM\GeneratedValue
234+
*
235+
* @ORM\Column(type="integer")
236+
*/
200237
private ?int $id = null;
201238

239+
/**
240+
* @ORM\Column
241+
*/
202242
#[Polyglot\Locale]
203-
#[ORM\Column]
204243
private string $locale;
205244

206-
#[ORM\ManyToOne(targetEntity: \EntityInheritance_ChildEntityClass::class, inversedBy: 'extraTranslations')]
245+
/**
246+
* @ORM\ManyToOne(targetEntity="EntityInheritance_ChildEntityClass", inversedBy="extraTranslations")
247+
*/
207248
private EntityInheritance_ChildEntityClass $entity;
208249

209-
#[ORM\Column]
250+
/**
251+
* @ORM\Column()
252+
*/
210253
private string $extraText;
211254
}

tests/Functional/StronglyTypedTranslationsTest.php

+34-13
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,33 @@ public function flush_updated_entity_two_times_does_not_update(): void
188188
}
189189
}
190190

191+
/**
192+
* @ORM\Entity
193+
*/
191194
#[Polyglot\Locale(primary: 'en_GB')]
192-
#[ORM\Entity]
193195
class StronglyTypedTranslationsTest_Entity
194196
{
195-
#[ORM\Column(type: 'integer')]
196-
#[ORM\Id]
197-
#[ORM\GeneratedValue]
197+
/**
198+
* @ORM\Column(type="integer")
199+
*
200+
* @ORM\Id
201+
*
202+
* @ORM\GeneratedValue
203+
*/
198204
public ?int $id = null;
199205

206+
/**
207+
* @ORM\OneToMany(targetEntity="StronglyTypedTranslationsTest_Translation", mappedBy="entity")
208+
*/
200209
#[Polyglot\TranslationCollection]
201-
#[ORM\OneToMany(targetEntity: \StronglyTypedTranslationsTest_Translation::class, mappedBy: 'entity')]
202210
public Collection $translations;
203211

204212
/**
205213
* @var TranslatableInterface<string>
214+
*
215+
* @ORM\Column(type="translatable_string", options={"use_text_column": true})
206216
*/
207217
#[Polyglot\Translatable]
208-
#[ORM\Column(type: 'translatable_string', options: ['use_text_column' => true])]
209218
public TranslatableInterface $text;
210219

211220
public function __construct()
@@ -215,21 +224,33 @@ public function __construct()
215224
}
216225
}
217226

218-
#[ORM\Entity]
227+
/**
228+
* @ORM\Entity
229+
*/
219230
class StronglyTypedTranslationsTest_Translation
220231
{
221-
#[ORM\Id]
222-
#[ORM\GeneratedValue]
223-
#[ORM\Column(type: 'integer')]
232+
/**
233+
* @ORM\Id
234+
*
235+
* @ORM\GeneratedValue
236+
*
237+
* @ORM\Column(type="integer")
238+
*/
224239
public ?int $id = null;
225240

241+
/**
242+
* @ORM\Column
243+
*/
226244
#[Polyglot\Locale]
227-
#[ORM\Column]
228245
public string $locale;
229246

230-
#[ORM\ManyToOne(targetEntity: \StronglyTypedTranslationsTest_Entity::class, inversedBy: 'translations')]
247+
/**
248+
* @ORM\ManyToOne(targetEntity="StronglyTypedTranslationsTest_Entity", inversedBy="translations")
249+
*/
231250
public StronglyTypedTranslationsTest_Entity $entity;
232251

233-
#[ORM\Column]
252+
/**
253+
* @ORM\Column
254+
*/
234255
public string $text;
235256
}

tests/Functional/TranslatableWithObjectDataTest.php

+35-13
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,31 @@ public function flushing_updates_and_reloading_provides_translatables(): void
117117
}
118118
}
119119

120+
/**
121+
* @ORM\Entity
122+
*/
120123
#[Polyglot\Locale(primary: 'en_GB')]
121-
#[ORM\Entity]
122124
class TranslatableWithObjectDataTest_Entity
123125
{
124-
#[ORM\Column(type: 'integer')]
125-
#[ORM\Id]
126-
#[ORM\GeneratedValue]
126+
/**
127+
* @ORM\Column(type="integer")
128+
*
129+
* @ORM\Id
130+
*
131+
* @ORM\GeneratedValue
132+
*/
127133
public ?int $id = null;
128134

135+
/**
136+
* @ORM\OneToMany(targetEntity="TranslatableWithObjectDataTest_Translation", mappedBy="entity")
137+
*/
129138
#[Polyglot\TranslationCollection]
130-
#[ORM\OneToMany(targetEntity: \TranslatableWithObjectDataTest_Translation::class, mappedBy: 'entity')]
131139
public Collection $translations;
132140

141+
/**
142+
* @ORM\Column(type="object")
143+
*/
133144
#[Polyglot\Translatable]
134-
#[ORM\Column(type: 'object')]
135145
public TranslatableInterface|TranslatableWithObjectDataTest_Object $data;
136146

137147
public function __construct()
@@ -141,22 +151,34 @@ public function __construct()
141151
}
142152
}
143153

144-
#[ORM\Entity]
154+
/**
155+
* @ORM\Entity
156+
*/
145157
class TranslatableWithObjectDataTest_Translation
146158
{
147-
#[ORM\Id]
148-
#[ORM\GeneratedValue]
149-
#[ORM\Column(type: 'integer')]
159+
/**
160+
* @ORM\Id
161+
*
162+
* @ORM\GeneratedValue
163+
*
164+
* @ORM\Column(type="integer")
165+
*/
150166
private ?int $id = null;
151167

168+
/**
169+
* @ORM\Column
170+
*/
152171
#[Polyglot\Locale]
153-
#[ORM\Column]
154172
private string $locale;
155173

156-
#[ORM\ManyToOne(targetEntity: \TranslatableWithObjectDataTest_Entity::class, inversedBy: 'translations')]
174+
/**
175+
* @ORM\ManyToOne(targetEntity="TranslatableWithObjectDataTest_Entity", inversedBy="translations")
176+
*/
157177
private TranslatableWithObjectDataTest_Entity $entity;
158178

159-
#[ORM\Column(type: 'object')]
179+
/**
180+
* @ORM\Column(type="object")
181+
*/
160182
private TranslatableWithObjectDataTest_Object $data;
161183
}
162184

0 commit comments

Comments
 (0)