diff --git a/composer.json b/composer.json index a51ead7..1ce539c 100644 --- a/composer.json +++ b/composer.json @@ -36,10 +36,10 @@ }, "require-dev": { - "phpunit/phpunit": "^8.5.36|^9.6", - "symfony/error-handler": "^5.4|^6.4|^7.0", + "phpunit/phpunit": "^9.6.18", + "symfony/error-handler": "^6.4|^7.0", "symfony/phpunit-bridge": ">= 7.0", - "webfactory/doctrine-orm-test-infrastructure": "^1.9" + "webfactory/doctrine-orm-test-infrastructure": "^1.14" }, "config": { diff --git a/tests/Doctrine/TranslatableClassMetadataTest.php b/tests/Doctrine/TranslatableClassMetadataTest.php index e977b9c..558574e 100644 --- a/tests/Doctrine/TranslatableClassMetadataTest.php +++ b/tests/Doctrine/TranslatableClassMetadataTest.php @@ -2,6 +2,7 @@ namespace Webfactory\Bundle\PolyglotBundle\Tests\Doctrine; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use PHPUnit\Framework\TestCase; use Webfactory\Bundle\PolyglotBundle\Doctrine\TranslatableClassMetadata; use Webfactory\Bundle\PolyglotBundle\Tests\TestEntity; @@ -28,7 +29,7 @@ private function createMetadata(): TranslatableClassMetadata $infrastructure = new ORMInfrastructure([ TestEntity::class, TestEntityTranslation::class, - ]); + ], mappingDriver: new AttributeDriver([], true)); $entityManager = $infrastructure->getEntityManager(); return TranslatableClassMetadata::parseFromClass(TestEntity::class, $entityManager->getMetadataFactory()); diff --git a/tests/Functional/CascadePersistTranslationsTest.php b/tests/Functional/CascadePersistTranslationsTest.php index 6fb4def..ef83b41 100644 --- a/tests/Functional/CascadePersistTranslationsTest.php +++ b/tests/Functional/CascadePersistTranslationsTest.php @@ -44,33 +44,24 @@ 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() @@ -85,33 +76,21 @@ 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", inversedBy="translations") - */ + #[ORM\ManyToOne(targetEntity: \CascadePersistTranslationsTest_Entity::class, 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 3e4defe..e41e001 100644 --- a/tests/Functional/EntityInheritanceTest.php +++ b/tests/Functional/EntityInheritanceTest.php @@ -101,39 +101,26 @@ 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() @@ -157,52 +144,34 @@ 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", inversedBy="translations") - */ + #[ORM\ManyToOne(targetEntity: \EntityInheritance_BaseEntityClass::class, 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() @@ -222,33 +191,21 @@ 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", inversedBy="extraTranslations") - */ + #[ORM\ManyToOne(targetEntity: \EntityInheritance_ChildEntityClass::class, inversedBy: 'extraTranslations')] private EntityInheritance_ChildEntityClass $entity; - /** - * @ORM\Column() - */ + #[ORM\Column] private string $extraText; } diff --git a/tests/Functional/FunctionalTestBase.php b/tests/Functional/FunctionalTestBase.php index 312b68f..46d2200 100644 --- a/tests/Functional/FunctionalTestBase.php +++ b/tests/Functional/FunctionalTestBase.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use PHPUnit\Framework\TestCase; use Webfactory\Bundle\PolyglotBundle\Doctrine\PolyglotListener; use Webfactory\Bundle\PolyglotBundle\Doctrine\TranslatableStringType; @@ -22,7 +23,7 @@ protected function setupOrmInfrastructure(array $classes): void if (!Type::hasType(TranslatableStringType::NAME)) { Type::addType(TranslatableStringType::NAME, TranslatableStringType::class); } - $this->infrastructure = ORMInfrastructure::createOnlyFor($classes); + $this->infrastructure = ORMInfrastructure::createOnlyFor($classes, mappingDriver: new AttributeDriver([], true)); $this->entityManager = $this->infrastructure->getEntityManager(); $this->defaultLocaleProvider = new DefaultLocaleProvider('en_GB'); diff --git a/tests/Functional/StronglyTypedTranslationsTest.php b/tests/Functional/StronglyTypedTranslationsTest.php index 89905c3..84cefac 100644 --- a/tests/Functional/StronglyTypedTranslationsTest.php +++ b/tests/Functional/StronglyTypedTranslationsTest.php @@ -188,33 +188,24 @@ 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() @@ -224,33 +215,21 @@ 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", inversedBy="translations") - */ + #[ORM\ManyToOne(targetEntity: \StronglyTypedTranslationsTest_Entity::class, 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 241b1be..7a78437 100644 --- a/tests/Functional/TranslatableWithObjectDataTest.php +++ b/tests/Functional/TranslatableWithObjectDataTest.php @@ -117,31 +117,21 @@ 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() @@ -151,34 +141,22 @@ 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", inversedBy="translations") - */ + #[ORM\ManyToOne(targetEntity: \TranslatableWithObjectDataTest_Entity::class, 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 fbe33e1..fd47222 100644 --- a/tests/Functional/TranslationPropertyNamedDifferentlyTest.php +++ b/tests/Functional/TranslationPropertyNamedDifferentlyTest.php @@ -80,31 +80,21 @@ 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() @@ -128,33 +118,21 @@ 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", inversedBy="translations") - */ + #[ORM\ManyToOne(targetEntity: \TranslationPropertyNamedDifferently_Entity::class, 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 bc8e9d0..f4489c8 100644 --- a/tests/Functional/UndeclaredBaseClassTest.php +++ b/tests/Functional/UndeclaredBaseClassTest.php @@ -89,25 +89,17 @@ 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() @@ -131,41 +123,27 @@ 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", inversedBy="translations") - */ + #[ORM\ManyToOne(targetEntity: \UndeclaredBaseClassTest_EntityClass::class, 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 e0157c7..43c5b4a 100644 --- a/tests/TestEntity.php +++ b/tests/TestEntity.php @@ -11,42 +11,32 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use TestEntityTranslation; use Webfactory\Bundle\PolyglotBundle\Attribute as Polyglot; use Webfactory\Bundle\PolyglotBundle\TranslatableInterface; /** * 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 dccac9b..5a4d59e 100644 --- a/tests/TestEntityTranslation.php +++ b/tests/TestEntityTranslation.php @@ -14,16 +14,14 @@ /** * 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; /** @@ -31,10 +29,9 @@ 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; /**