diff --git a/src/Entity/BaseTranslation.php b/src/Entity/BaseTranslation.php index 88c8793..021fbc1 100644 --- a/src/Entity/BaseTranslation.php +++ b/src/Entity/BaseTranslation.php @@ -16,7 +16,6 @@ /** * @ORM\MappedSuperclass */ -#[ORM\MappedSuperclass] class BaseTranslation { /** @@ -26,9 +25,6 @@ class BaseTranslation * * @ORM\Column(type="integer") */ - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] protected $id; /** @@ -37,13 +33,11 @@ class BaseTranslation * @PolyglotAnnotation\Locale */ #[Polyglot\Locale] - #[ORM\Column] protected $locale; /** * @ORM\JoinColumn(name="entity_id", referencedColumnName="id", nullable=false) */ - #[ORM\JoinColumn(name: 'entity_id', referencedColumnName: 'id', nullable: false)] protected $entity; public function getLocale() diff --git a/tests/Functional/CascadePersistTranslationsTest.php b/tests/Functional/CascadePersistTranslationsTest.php index ea0c061..6fb4def 100644 --- a/tests/Functional/CascadePersistTranslationsTest.php +++ b/tests/Functional/CascadePersistTranslationsTest.php @@ -44,25 +44,33 @@ public function adding_and_persisting_translations(): void } } +/** + * @ORM\Entity + */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] class CascadePersistTranslationsTest_Entity { - - #[ORM\Column(type: 'integer')] - #[ORM\Id] - #[ORM\GeneratedValue] + /** + * @ORM\Column(type="integer") + * + * @ORM\Id + * + * @ORM\GeneratedValue + */ private ?int $id = null; /** * (!) There is *not* cascade="persist" configuration here. + * + * @ORM\OneToMany(targetEntity="CascadePersistTranslationsTest_Translation", mappedBy="entity") */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \CascadePersistTranslationsTest_Translation::class, mappedBy: 'entity')] protected Collection $translations; + /** + * @ORM\Column(type="string") + */ #[Polyglot\Translatable] - #[ORM\Column(type: 'string')] protected string|TranslatableInterface $text; public function __construct() @@ -77,22 +85,33 @@ public function addTranslation(string $locale, mixed $text): void } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class CascadePersistTranslationsTest_Translation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ private ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] private string $locale; - #[ORM\ManyToOne(targetEntity: \CascadePersistTranslationsTest_Entity::class, inversedBy: 'translations')] + /** + * @ORM\ManyToOne(targetEntity="CascadePersistTranslationsTest_Entity", inversedBy="translations") + */ private CascadePersistTranslationsTest_Entity $entity; - #[ORM\Column] + /** + * @ORM\Column + */ private string $text; } diff --git a/tests/Functional/EntityInheritanceTest.php b/tests/Functional/EntityInheritanceTest.php index 87f3e8c..3e4defe 100644 --- a/tests/Functional/EntityInheritanceTest.php +++ b/tests/Functional/EntityInheritanceTest.php @@ -101,28 +101,39 @@ public function testUpdateTranslations(): void } } - +/** + * @ORM\Entity() + * + * @ORM\InheritanceType(value="SINGLE_TABLE") + * + * @ORM\DiscriminatorMap({"base"="EntityInheritance_BaseEntityClass", "child"="EntityInheritance_ChildEntityClass"}) + * + * @ORM\DiscriminatorColumn(name="discriminator", type="string") + */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] -#[ORM\InheritanceType(value: 'SINGLE_TABLE')] -#[ORM\DiscriminatorMap(['base' => 'EntityInheritance_BaseEntityClass', 'child' => 'EntityInheritance_ChildEntityClass'])] -#[ORM\DiscriminatorColumn(name: 'discriminator', type: 'string')] class EntityInheritance_BaseEntityClass { - - #[ORM\Column(type: 'integer')] - #[ORM\Id] - #[ORM\GeneratedValue] + /** + * @ORM\Column(type="integer") + * + * @ORM\Id + * + * @ORM\GeneratedValue + */ private ?int $id = null; private string $discriminator; + /** + * @ORM\OneToMany(targetEntity="EntityInheritance_BaseEntityClassTranslation", mappedBy="entity") + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \EntityInheritance_BaseEntityClassTranslation::class, mappedBy: 'entity')] private Collection $translations; + /** + * @ORM\Column(type="string") + */ #[Polyglot\Translatable] - #[ORM\Column(type: 'string')] private TranslatableInterface|string|null $text = null; public function __construct() @@ -146,35 +157,52 @@ public function getText(): TranslatableInterface } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class EntityInheritance_BaseEntityClassTranslation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ private ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] private string $locale; - #[ORM\ManyToOne(targetEntity: \EntityInheritance_BaseEntityClass::class, inversedBy: 'translations')] + /** + * @ORM\ManyToOne(targetEntity="EntityInheritance_BaseEntityClass", inversedBy="translations") + */ private EntityInheritance_BaseEntityClass $entity; - #[ORM\Column] + /** + * @ORM\Column() + */ private string $text; } -#[ORM\Entity] +/** + * @ORM\Entity + */ class EntityInheritance_ChildEntityClass extends EntityInheritance_BaseEntityClass { + /** + * @ORM\Column(type="string") + */ #[Polyglot\Translatable] - #[ORM\Column(type: 'string')] private TranslatableInterface|string|null $extraText = null; + /** + * @ORM\OneToMany(targetEntity="EntityInheritance_ChildEntityClassTranslation", mappedBy="entity") + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \EntityInheritance_ChildEntityClassTranslation::class, mappedBy: 'entity')] private Collection $extraTranslations; public function __construct() @@ -194,22 +222,33 @@ public function getExtraText(): TranslatableInterface } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class EntityInheritance_ChildEntityClassTranslation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ private ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] private string $locale; - #[ORM\ManyToOne(targetEntity: \EntityInheritance_ChildEntityClass::class, inversedBy: 'extraTranslations')] + /** + * @ORM\ManyToOne(targetEntity="EntityInheritance_ChildEntityClass", inversedBy="extraTranslations") + */ private EntityInheritance_ChildEntityClass $entity; - #[ORM\Column] + /** + * @ORM\Column() + */ private string $extraText; } diff --git a/tests/Functional/StronglyTypedTranslationsTest.php b/tests/Functional/StronglyTypedTranslationsTest.php index f364a2c..89905c3 100644 --- a/tests/Functional/StronglyTypedTranslationsTest.php +++ b/tests/Functional/StronglyTypedTranslationsTest.php @@ -188,25 +188,33 @@ public function flush_updated_entity_two_times_does_not_update(): void } } +/** + * @ORM\Entity + */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] class StronglyTypedTranslationsTest_Entity { - - #[ORM\Column(type: 'integer')] - #[ORM\Id] - #[ORM\GeneratedValue] + /** + * @ORM\Column(type="integer") + * + * @ORM\Id + * + * @ORM\GeneratedValue + */ public ?int $id = null; + /** + * @ORM\OneToMany(targetEntity="StronglyTypedTranslationsTest_Translation", mappedBy="entity") + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \StronglyTypedTranslationsTest_Translation::class, mappedBy: 'entity')] public Collection $translations; /** * @var TranslatableInterface + * + * @ORM\Column(type="translatable_string", options={"use_text_column": true}) */ #[Polyglot\Translatable] - #[ORM\Column(type: 'translatable_string', options: ['use_text_column' => true])] public TranslatableInterface $text; public function __construct() @@ -216,22 +224,33 @@ public function __construct() } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class StronglyTypedTranslationsTest_Translation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ public ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] public string $locale; - #[ORM\ManyToOne(targetEntity: \StronglyTypedTranslationsTest_Entity::class, inversedBy: 'translations')] + /** + * @ORM\ManyToOne(targetEntity="StronglyTypedTranslationsTest_Entity", inversedBy="translations") + */ public StronglyTypedTranslationsTest_Entity $entity; - #[ORM\Column] + /** + * @ORM\Column + */ public string $text; } diff --git a/tests/Functional/TranslatableWithObjectDataTest.php b/tests/Functional/TranslatableWithObjectDataTest.php index b96684f..241b1be 100644 --- a/tests/Functional/TranslatableWithObjectDataTest.php +++ b/tests/Functional/TranslatableWithObjectDataTest.php @@ -117,22 +117,31 @@ public function flushing_updates_and_reloading_provides_translatables(): void } } +/** + * @ORM\Entity + */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] class TranslatableWithObjectDataTest_Entity { - - #[ORM\Column(type: 'integer')] - #[ORM\Id] - #[ORM\GeneratedValue] + /** + * @ORM\Column(type="integer") + * + * @ORM\Id + * + * @ORM\GeneratedValue + */ public ?int $id = null; + /** + * @ORM\OneToMany(targetEntity="TranslatableWithObjectDataTest_Translation", mappedBy="entity") + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \TranslatableWithObjectDataTest_Translation::class, mappedBy: 'entity')] public Collection $translations; + /** + * @ORM\Column(type="object") + */ #[Polyglot\Translatable] - #[ORM\Column(type: 'object')] public TranslatableInterface|TranslatableWithObjectDataTest_Object $data; public function __construct() @@ -142,23 +151,34 @@ public function __construct() } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class TranslatableWithObjectDataTest_Translation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ private ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] private string $locale; - #[ORM\ManyToOne(targetEntity: \TranslatableWithObjectDataTest_Entity::class, inversedBy: 'translations')] + /** + * @ORM\ManyToOne(targetEntity="TranslatableWithObjectDataTest_Entity", inversedBy="translations") + */ private TranslatableWithObjectDataTest_Entity $entity; - #[ORM\Column(type: 'object')] + /** + * @ORM\Column(type="object") + */ private TranslatableWithObjectDataTest_Object $data; } diff --git a/tests/Functional/TranslationPropertyNamedDifferentlyTest.php b/tests/Functional/TranslationPropertyNamedDifferentlyTest.php index 7b6d7e2..fbe33e1 100644 --- a/tests/Functional/TranslationPropertyNamedDifferentlyTest.php +++ b/tests/Functional/TranslationPropertyNamedDifferentlyTest.php @@ -80,22 +80,31 @@ public function testUpdateTranslations(): void } } +/** + * @ORM\Entity + */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] class TranslationPropertyNamedDifferently_Entity { - - #[ORM\Column(type: 'integer')] - #[ORM\Id] - #[ORM\GeneratedValue] + /** + * @ORM\Column(type="integer") + * + * @ORM\Id + * + * @ORM\GeneratedValue + */ private ?int $id = null; + /** + * @ORM\OneToMany(targetEntity="TranslationPropertyNamedDifferently_Translation", mappedBy="entity") + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \TranslationPropertyNamedDifferently_Translation::class, mappedBy: 'entity')] protected Collection $translations; + /** + * @ORM\Column(type="string") + */ #[Polyglot\Translatable(translationFieldname: 'textOtherName')] - #[ORM\Column(type: 'string')] protected string|TranslatableInterface|null $text = null; public function __construct() @@ -119,22 +128,33 @@ public function getText(): ?TranslatableInterface } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class TranslationPropertyNamedDifferently_Translation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ private ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] private string $locale; - #[ORM\ManyToOne(targetEntity: \TranslationPropertyNamedDifferently_Entity::class, inversedBy: 'translations')] + /** + * @ORM\ManyToOne(targetEntity="TranslationPropertyNamedDifferently_Entity", inversedBy="translations") + */ private TranslationPropertyNamedDifferently_Entity $entity; - #[ORM\Column] + /** + * @ORM\Column + */ private string $textOtherName; } diff --git a/tests/Functional/UndeclaredBaseClassTest.php b/tests/Functional/UndeclaredBaseClassTest.php index d298e25..bc8e9d0 100644 --- a/tests/Functional/UndeclaredBaseClassTest.php +++ b/tests/Functional/UndeclaredBaseClassTest.php @@ -89,18 +89,25 @@ public function testUpdateTranslations(): void */ class UndeclaredBaseClassTest_BaseClass { - - #[ORM\Column(type: 'integer')] - #[ORM\Id] - #[ORM\GeneratedValue] + /** + * @ORM\Column(type="integer") + * + * @ORM\Id + * + * @ORM\GeneratedValue + */ protected ?int $id = null; + /** + * @ORM\OneToMany(targetEntity="UndeclaredBaseClassTest_BaseClassTranslation", mappedBy="entity") + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \UndeclaredBaseClassTest_BaseClassTranslation::class, mappedBy: 'entity')] protected Collection $translations; + /** + * @ORM\Column(type="string") + */ #[Polyglot\Translatable] - #[ORM\Column(type: 'string')] protected string|TranslatableInterface|null $text = null; public function __construct() @@ -124,28 +131,41 @@ public function getText(): ?TranslatableInterface } } -#[ORM\Entity] +/** + * @ORM\Entity + */ class UndeclaredBaseClassTest_BaseClassTranslation { - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] + /** + * @ORM\Id + * + * @ORM\GeneratedValue + * + * @ORM\Column(type="integer") + */ private ?int $id = null; + /** + * @ORM\Column + */ #[Polyglot\Locale] - #[ORM\Column] private string $locale; - #[ORM\ManyToOne(targetEntity: \UndeclaredBaseClassTest_EntityClass::class, inversedBy: 'translations')] + /** + * @ORM\ManyToOne(targetEntity="UndeclaredBaseClassTest_EntityClass", inversedBy="translations") + */ private UndeclaredBaseClassTest_EntityClass $entity; - #[ORM\Column] + /** + * @ORM\Column + */ private string $text; } +/** + * @ORM\Entity + */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] class UndeclaredBaseClassTest_EntityClass extends UndeclaredBaseClassTest_BaseClass { } diff --git a/tests/TestEntity.php b/tests/TestEntity.php index af8104a..e0157c7 100644 --- a/tests/TestEntity.php +++ b/tests/TestEntity.php @@ -16,27 +16,37 @@ /** * Doctrine entity that is used for testing. + * + * @ORM\Entity() */ #[Polyglot\Locale(primary: 'en_GB')] -#[ORM\Entity] class TestEntity { - - #[ORM\Id] - #[ORM\Column(type: 'integer')] - #[ORM\GeneratedValue] + /** + * @ORM\Id + * + * @ORM\Column(type="integer") + * + * @ORM\GeneratedValue + */ private ?int $id = null; /** * Text in the primary locale. Can be set with a string and gets replaced with a TranslatableInterface by the * Doctrine PolyglotListener. + * + * @ORM\Column(type="string") */ #[Polyglot\Translatable] - #[ORM\Column(type: 'string')] private TranslatableInterface|string|null $text; + /** + * @ORM\OneToMany(targetEntity="TestEntityTranslation", mappedBy="entity") + * + * This property is currently not typed to avoid an error in the \Webfactory\Bundle\PolyglotBundle\Tests\Doctrine\TranslatableClassMetadataTest::can_be_serialized_and_retrieved + * test; Doctrine uses specialized Reflection subclasses to do ... what ?!. + */ #[Polyglot\TranslationCollection] - #[ORM\OneToMany(targetEntity: \TestEntityTranslation::class, mappedBy: 'entity')] // This property is currently not typed to avoid an error in the \Webfactory\Bundle\PolyglotBundle\Tests\Doctrine\TranslatableClassMetadataTest::can_be_serialized_and_retrieved private $translations; public function __construct($text) diff --git a/tests/TestEntityTranslation.php b/tests/TestEntityTranslation.php index 80546cb..dccac9b 100644 --- a/tests/TestEntityTranslation.php +++ b/tests/TestEntityTranslation.php @@ -14,14 +14,16 @@ /** * Translation entity of the Doctrine entity that is used for testing. + * + * @ORM\Entity */ -#[ORM\Entity] class TestEntityTranslation extends BaseTranslation { /** + * @ORM\ManyToOne(targetEntity="TestEntity", inversedBy="translations") + * * @var TestEntity */ - #[ORM\ManyToOne(targetEntity: \TestEntity::class, inversedBy: 'translations')] protected $entity; /** @@ -29,10 +31,10 @@ class TestEntityTranslation extends BaseTranslation * * Must be protected to be usable when this class is used as base for a mock. * + * @ORM\Column(type="string") * * @var string */ - #[ORM\Column(type: 'string')] protected $text; /**