diff --git a/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.User.dcm.xml b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.User.dcm.xml new file mode 100644 index 0000000000..33358fed1c --- /dev/null +++ b/tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.User.dcm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Gedmo/Mapping/ExtensionORMTest.php b/tests/Gedmo/Mapping/ExtensionORMTest.php index e8831077ab..efc156952c 100644 --- a/tests/Gedmo/Mapping/ExtensionORMTest.php +++ b/tests/Gedmo/Mapping/ExtensionORMTest.php @@ -58,6 +58,7 @@ public function testGeneratedValues(): void $user = new User(); $user->setName('encode me'); $user->setPassword('secret'); + $user->setUsername('some_username'); $this->em->persist($user); $this->em->flush(); diff --git a/tests/Gedmo/Mapping/Fixture/User.php b/tests/Gedmo/Mapping/Fixture/User.php index fe3949ab33..9a5a6058cd 100644 --- a/tests/Gedmo/Mapping/Fixture/User.php +++ b/tests/Gedmo/Mapping/Fixture/User.php @@ -13,14 +13,24 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Tests\Mapping\Mock\Extension\Encoder\Mapping as Ext; +use Gedmo\Tests\Translatable\Fixture\PersonTranslation; /** - * @ORM\Table(name="test_users") + * @ORM\Table(name="users") + * @ORM\Table( + * name="users", + * indexes={@ORM\Index(name="search_idx", columns={"username"})} + * ) * @ORM\Entity + * + * @Gedmo\TranslationEntity(class="Gedmo\Tests\Translatable\Fixture\PersonTranslation") */ -#[ORM\Table(name: 'test_users')] +#[ORM\Table(name: 'users')] #[ORM\Entity] +#[ORM\Index(columns: ['username'], name: 'search_idx')] +#[Gedmo\TranslationEntity(class: PersonTranslation::class)] class User { /** @@ -48,11 +58,40 @@ class User * @Ext\Encode(type="md5") * * @ORM\Column(length=32) + * + * @Gedmo\Translatable */ #[Ext\Encode(type: 'md5')] #[ORM\Column(length: 32)] + #[Gedmo\Translatable] private ?string $password = null; + /** + * @ORM\Column(length=128) + * + * @Gedmo\Translatable + */ + #[ORM\Column(length: 128)] + #[Gedmo\Translatable] + private ?string $username = null; + + /** + * @ORM\Column(length=128, nullable=true) + * + * @Gedmo\Translatable(fallback=true) + */ + #[ORM\Column(length: 128, nullable: true)] + #[Gedmo\Translatable(fallback: true)] + private ?string $company = null; + + /** + * @var string + * + * @Gedmo\Locale + */ + #[Gedmo\Locale] + private $localeField; + public function setName(?string $name): void { $this->name = $name; @@ -72,4 +111,24 @@ public function getPassword(): ?string { return $this->password; } + + public function setUsername(string $username): void + { + $this->username = $username; + } + + public function getUsername(): string + { + return $this->username; + } + + public function setCompany(string $company): void + { + $this->company = $company; + } + + public function getCompany(): string + { + return $this->company; + } } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/User.php b/tests/Gedmo/Mapping/Fixture/Xml/User.php new file mode 100644 index 0000000000..9972cc2844 --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/Xml/User.php @@ -0,0 +1,66 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Tests\Mapping\Fixture\Xml; + +class User +{ + /** + * @var int + */ + private $id; + + private ?string $password = null; + + private ?string $username = null; + + private ?string $company = null; + + /** + * @var string + */ + private $localeField; + + public function getId(): int + { + return $this->id; + } + + public function setPassword(string $password): void + { + $this->password = $password; + } + + public function getPassword(): string + { + return $this->password; + } + + public function setUsername(string $username): void + { + $this->username = $username; + } + + public function getUsername(): string + { + return $this->username; + } + + public function setCompany(string $company): void + { + $this->company = $company; + } + + public function getCompany(): string + { + return $this->company; + } +} diff --git a/tests/Gedmo/Mapping/LoggableORMMappingTest.php b/tests/Gedmo/Mapping/LoggableORMMappingTest.php index d60c02aefe..07fd5bf87f 100644 --- a/tests/Gedmo/Mapping/LoggableORMMappingTest.php +++ b/tests/Gedmo/Mapping/LoggableORMMappingTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Loggable\Entity\LogEntry; use Gedmo\Loggable\LoggableListener; @@ -58,7 +57,7 @@ protected function setUp(): void */ public static function dataLoggableObject(): \Generator { - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedLoggable::class]; } @@ -120,7 +119,7 @@ public static function dataLoggableObjectWithCompositeKey(): \Generator { yield 'Model with XML mapping' => [XmlLoggableComposite::class]; - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedLoggableComposite::class]; } @@ -165,7 +164,7 @@ public static function dataLoggableObjectWithCompositeKeyAndRelation(): \Generat { yield 'Model with XML mapping' => [XmlLoggableCompositeRelation::class]; - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedLoggableCompositeRelation::class]; } @@ -213,7 +212,7 @@ public function testLoggableCompositeRelationMapping(string $className): void */ public static function dataLoggableObjectWithEmbedded(): \Generator { - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedLoggableWithEmbedded::class]; } diff --git a/tests/Gedmo/Mapping/MappingEventSubscriberTest.php b/tests/Gedmo/Mapping/MappingEventSubscriberTest.php index 5c051dcc00..adbe71f8d6 100644 --- a/tests/Gedmo/Mapping/MappingEventSubscriberTest.php +++ b/tests/Gedmo/Mapping/MappingEventSubscriberTest.php @@ -12,8 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; @@ -24,7 +22,6 @@ use Gedmo\Tests\Mapping\Fixture\SuperClassExtension; use Gedmo\Tests\Mapping\Mock\Extension\Encoder\EncoderListener; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\ArrayAdapter; final class MappingEventSubscriberTest extends ORMMappingTestCase { @@ -36,18 +33,13 @@ protected function setUp(): void $config = $this->getBasicConfiguration(); - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { $config->setMetadataDriverImpl(new AttributeDriver([])); } else { $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); } - $conn = [ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]; - - $this->em = new EntityManager(DriverManager::getConnection($conn, $config), $config, new EventManager()); + $this->em = $this->getBasicEntityManager($config); } public function testGetMetadataFactoryCacheFromDoctrineForSluggable(): void @@ -95,20 +87,13 @@ public function testGetMetadataFactoryCacheFromDoctrineForSuperClassExtension(): // Create new configuration to use new array cache $config = $this->getBasicConfiguration(); - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { $config->setMetadataDriverImpl(new AttributeDriver([])); } else { $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); } - $config->setMetadataCache(new ArrayAdapter()); - - $conn = [ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]; - - $this->em = new EntityManager(DriverManager::getConnection($conn, $config), $config, new EventManager()); + $this->em = $this->getBasicEntityManager($config); $config = $subscriber->getExtensionMetadataFactory($this->em)->getExtensionMetadata($classMetadata); diff --git a/tests/Gedmo/Mapping/MappingTest.php b/tests/Gedmo/Mapping/MappingTest.php index 8b628d047a..4a9432ad56 100644 --- a/tests/Gedmo/Mapping/MappingTest.php +++ b/tests/Gedmo/Mapping/MappingTest.php @@ -45,9 +45,8 @@ protected function setUp(): void $config = new Configuration(); $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\Mapping\Proxy'); - // $this->markTestSkipped('Skipping according to a bug in annotation reader creation.'); - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { $config->setMetadataDriverImpl(new AttributeDriver([])); } else { $config->setMetadataDriverImpl(new AnnotationDriver($_ENV['annotation_reader'])); diff --git a/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php b/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php index eed7d7c82e..ca687cdd9e 100644 --- a/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php +++ b/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php @@ -15,7 +15,6 @@ use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\Id\IdentityGenerator; @@ -23,6 +22,7 @@ use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Tools\SchemaTool; +use Gedmo\Mapping\Driver\AttributeReader; use Gedmo\Tests\Mapping\Fixture\Unmapped\Timestampable; use Gedmo\Timestampable\TimestampableListener; use PHPUnit\Framework\TestCase; @@ -36,7 +36,7 @@ final class ForcedMetadataTest extends TestCase { private TimestampableListener $timestampable; - private EntityManagerInterface $em; + private EntityManager $em; protected function setUp(): void { @@ -44,22 +44,28 @@ protected function setUp(): void $config->setProxyDir(TESTS_TEMP_DIR); $config->setProxyNamespace('Gedmo\Mapping\Proxy'); - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { $config->setMetadataDriverImpl(new AttributeDriver([])); } else { $config->setMetadataDriverImpl(new AnnotationDriver($_ENV['annotation_reader'])); } - $conn = [ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]; + $this->timestampable = new TimestampableListener(); + + if (PHP_VERSION_ID >= 80000) { + $this->timestampable->setAnnotationReader(new AttributeReader()); + } else { + $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); + } $evm = new EventManager(); - $this->timestampable = new TimestampableListener(); - $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); $evm->addEventSubscriber($this->timestampable); - $connection = DriverManager::getConnection($conn, $config); + + $connection = DriverManager::getConnection([ + 'driver' => 'pdo_sqlite', + 'memory' => true, + ], $config); + $this->em = new EntityManager($connection, $config, $evm); } @@ -72,6 +78,8 @@ public function testShouldWork(): void $this->em, Timestampable::class ); + + // @todo: This assertion fails when run in isolation static::assertTrue(isset($conf['create'])); $test = new Timestampable(); diff --git a/tests/Gedmo/Mapping/MultiManagerMappingTest.php b/tests/Gedmo/Mapping/MultiManagerMappingTest.php index 833acaedb1..0fc1c7fba3 100644 --- a/tests/Gedmo/Mapping/MultiManagerMappingTest.php +++ b/tests/Gedmo/Mapping/MultiManagerMappingTest.php @@ -15,10 +15,12 @@ use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\YamlDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; +use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Tests\Mapping\Fixture\Yaml\User; -use Gedmo\Tests\Sluggable\Fixture\Document\Article; +use Gedmo\Tests\Mapping\Fixture\Xml\User; +use Gedmo\Tests\Sluggable\Fixture\Article as ArticleEntity; +use Gedmo\Tests\Sluggable\Fixture\Document\Article as ArticleDocument; use Gedmo\Tests\Tool\BaseTestCaseOM; use Gedmo\Tests\Translatable\Fixture\PersonTranslation; @@ -38,44 +40,53 @@ final class MultiManagerMappingTest extends BaseTestCaseOM protected function setUp(): void { parent::setUp(); - // EM with standard annotation mapping + + // EM with standard annotation/attribute mapping $this->em1 = $this->getDefaultMockSqliteEntityManager([ - \Gedmo\Tests\Sluggable\Fixture\Article::class, + ArticleEntity::class, ]); - // EM with yaml and annotation mapping - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - $reader = new AnnotationReader(); - $annotationDriver2 = new AnnotationDriver($reader); + // EM with XML and annotation/attribute mapping + if (PHP_VERSION_ID >= 80000) { + $annotationDriver = new AttributeDriver([]); + + $annotationDriver2 = new AttributeDriver([]); + } else { + $reader = new AnnotationReader(); + $annotationDriver = new AnnotationDriver($reader); - $yamlDriver = new YamlDriver(__DIR__.'/Driver/Yaml'); + $reader = new AnnotationReader(); + $annotationDriver2 = new AnnotationDriver($reader); + } + + $xmlDriver = new XmlDriver(__DIR__.'/Driver/Xml'); $chain = new MappingDriverChain(); $chain->addDriver($annotationDriver, 'Gedmo\Tests\Translatable\Fixture'); - $chain->addDriver($yamlDriver, 'Gedmo\Tests\Mapping\Fixture\Yaml'); + $chain->addDriver($xmlDriver, 'Gedmo\Tests\Mapping\Fixture\Xml'); $chain->addDriver($annotationDriver2, 'Gedmo\Translatable'); $this->em2 = $this->getDefaultMockSqliteEntityManager([ PersonTranslation::class, User::class, ], $chain); - // DM with standard annotation mapping + + // DM with standard annotation/attribute mapping $this->dm1 = $this->getMockDocumentManager('gedmo_extensions_test'); } public function testTwoDifferentManagers(): void { // Force metadata class loading. - $this->dm1->getClassMetadata(Article::class); - $dmArticle = new Article(); + $this->dm1->getClassMetadata(ArticleDocument::class); + $dmArticle = new ArticleDocument(); $dmArticle->setCode('code'); $dmArticle->setTitle('title'); $this->dm1->persist($dmArticle); $this->dm1->flush(); static::assertSame('title-code', $dmArticle->getSlug()); - $em1Article = new \Gedmo\Tests\Sluggable\Fixture\Article(); + $em1Article = new ArticleEntity(); $em1Article->setCode('code'); $em1Article->setTitle('title'); $this->em1->persist($em1Article); @@ -86,7 +97,7 @@ public function testTwoDifferentManagers(): void public function testTwoSameManagers(): void { - $em1Article = new \Gedmo\Tests\Sluggable\Fixture\Article(); + $em1Article = new ArticleEntity(); $em1Article->setCode('code'); $em1Article->setTitle('title'); $this->em1->persist($em1Article); diff --git a/tests/Gedmo/Mapping/ORMMappingTestCase.php b/tests/Gedmo/Mapping/ORMMappingTestCase.php index 57eaf50214..661e0275b1 100644 --- a/tests/Gedmo/Mapping/ORMMappingTestCase.php +++ b/tests/Gedmo/Mapping/ORMMappingTestCase.php @@ -74,7 +74,7 @@ final protected function createChainedMappingDriver(): MappingDriverChain $chain->addDriver(new YamlDriver(__DIR__.'/Driver/Yaml'), 'Gedmo\Tests\Mapping\Fixture\Yaml'); } - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { $chain->addDriver(new AttributeDriver([]), 'Gedmo\Tests\Mapping\Fixture'); } diff --git a/tests/Gedmo/Mapping/SluggableMappingTest.php b/tests/Gedmo/Mapping/SluggableMappingTest.php index b39e55de00..12ea9576f5 100644 --- a/tests/Gedmo/Mapping/SluggableMappingTest.php +++ b/tests/Gedmo/Mapping/SluggableMappingTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Sluggable\Handler\RelativeSlugHandler; @@ -50,7 +49,7 @@ public static function dataSluggableObject(): \Generator { yield 'Model with XML mapping' => [XmlSluggable::class]; - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedSluggable::class]; } diff --git a/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php b/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php index fc1db973b7..914e1528c5 100644 --- a/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php +++ b/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\SoftDeleteable\SoftDeleteableListener; @@ -49,7 +48,7 @@ public static function dataSoftDeleteableObject(): \Generator { yield 'Model with XML mapping' => [XmlSoftDeleteable::class]; - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedSoftDeleteable::class]; } diff --git a/tests/Gedmo/Mapping/SortableMappingTest.php b/tests/Gedmo/Mapping/SortableMappingTest.php index d81ea50924..63a77c792b 100644 --- a/tests/Gedmo/Mapping/SortableMappingTest.php +++ b/tests/Gedmo/Mapping/SortableMappingTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Sortable\SortableListener; @@ -43,14 +42,12 @@ protected function setUp(): void /** * @return \Generator - * - * @note the XML fixture has a different mapping from the other configs, so it is tested separately */ public static function dataSortableObject(): \Generator { yield 'Model with XML mapping' => [XmlSortable::class]; - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedSortable::class]; } diff --git a/tests/Gedmo/Mapping/TimestampableMappingTest.php b/tests/Gedmo/Mapping/TimestampableMappingTest.php index c547215ede..2922652f35 100644 --- a/tests/Gedmo/Mapping/TimestampableMappingTest.php +++ b/tests/Gedmo/Mapping/TimestampableMappingTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Tests\Mapping\Fixture\Category as AnnotatedCategory; @@ -48,7 +47,7 @@ protected function setUp(): void */ public static function dataTimestampableObject(): \Generator { - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedCategory::class]; } diff --git a/tests/Gedmo/Mapping/TranslatableMappingTest.php b/tests/Gedmo/Mapping/TranslatableMappingTest.php index e9eac352dc..f63ed3cc88 100644 --- a/tests/Gedmo/Mapping/TranslatableMappingTest.php +++ b/tests/Gedmo/Mapping/TranslatableMappingTest.php @@ -11,14 +11,13 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\EventManager; -use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\Mapping\ExtensionMetadataFactory; -use Gedmo\Tests\Mapping\Fixture\Yaml\User; +use Gedmo\Tests\Mapping\Fixture\User as AnnotatedUser; +use Gedmo\Tests\Mapping\Fixture\Xml\User as XmlUser; +use Gedmo\Tests\Mapping\Fixture\Yaml\User as YamlUser; use Gedmo\Tests\Translatable\Fixture\PersonTranslation; use Gedmo\Translatable\TranslatableListener; @@ -29,48 +28,52 @@ */ final class TranslatableMappingTest extends ORMMappingTestCase { - private const TEST_YAML_ENTITY_CLASS = User::class; - - private TranslatableListener $translatableListener; - - private EntityManagerInterface $em; + private EntityManager $em; protected function setUp(): void { parent::setUp(); - $config = $this->getBasicConfiguration(); + $listener = new TranslatableListener(); + $listener->setCacheItemPool($this->cache); + $listener->setTranslatableLocale('en_us'); - $chain = new MappingDriverChain(); + $this->em = $this->getBasicEntityManager(); + $this->em->getEventManager()->addEventSubscriber($listener); + } - // TODO - The ORM's YAML mapping is deprecated and removed in 3.0 - $chain->addDriver(new YamlDriver(__DIR__.'/Driver/Yaml'), 'Gedmo\Tests\Mapping\Fixture\Yaml'); + /** + * @return \Generator + */ + public static function dataSortableObject(): \Generator + { + yield 'Model with XML mapping' => [XmlUser::class]; - $config->setMetadataDriverImpl($chain); + if (PHP_VERSION_ID >= 80000) { + yield 'Model with attributes' => [AnnotatedUser::class]; + } - $conn = [ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]; + if (class_exists(AnnotationDriver::class)) { + yield 'Model with annotations' => [AnnotatedUser::class]; + } - $evm = new EventManager(); - $this->translatableListener = new TranslatableListener(); - $this->translatableListener->setCacheItemPool($this->cache); - $this->translatableListener->setTranslatableLocale('en_us'); - $evm->addEventSubscriber($this->translatableListener); - $connection = DriverManager::getConnection($conn, $config); - $this->em = new EntityManager($connection, $config, $evm); + if (class_exists(YamlDriver::class)) { + yield 'Model with YAML mapping' => [YamlUser::class]; + } } - public function testYamlMapping(): void + /** + * @param class-string $className + * + * @dataProvider dataSortableObject + */ + public function testTranslatableMapping(string $className): void { // Force metadata class loading. - $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS); - $cacheId = ExtensionMetadataFactory::getCacheId( - self::TEST_YAML_ENTITY_CLASS, - 'Gedmo\Translatable' - ); + $this->em->getClassMetadata($className); + $cacheId = ExtensionMetadataFactory::getCacheId($className, 'Gedmo\Translatable'); $config = $this->cache->getItem($cacheId)->get(); + static::assertArrayHasKey('translationClass', $config); static::assertSame(PersonTranslation::class, $config['translationClass']); static::assertArrayHasKey('fields', $config); diff --git a/tests/Gedmo/Mapping/TreeMappingTest.php b/tests/Gedmo/Mapping/TreeMappingTest.php index ff23759209..ad2fff79b6 100644 --- a/tests/Gedmo/Mapping/TreeMappingTest.php +++ b/tests/Gedmo/Mapping/TreeMappingTest.php @@ -12,8 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\EventManager; -use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; @@ -52,7 +50,7 @@ protected function setUp(): void // TODO - The ORM's YAML mapping is deprecated and removed in 3.0 $chain->addDriver(new YamlDriver(__DIR__.'/Driver/Yaml'), 'Gedmo\Tests\Mapping\Fixture\Yaml'); - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { $annotationOrAttributeDriver = new AttributeDriver([]); } else { $annotationOrAttributeDriver = new AnnotationDriver(new AnnotationReader()); @@ -63,17 +61,11 @@ protected function setUp(): void $config->setMetadataDriverImpl($chain); - $conn = [ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]; - $this->listener = new TreeListener(); $this->listener->setCacheItemPool($this->cache); - $evm = new EventManager(); - $evm->addEventSubscriber($this->listener); - $connection = DriverManager::getConnection($conn, $config); - $this->em = new EntityManager($connection, $config, $evm); + + $this->em = $this->getBasicEntityManager($config); + $this->em->getEventManager()->addEventSubscriber($this->listener); } /** diff --git a/tests/Gedmo/Mapping/UploadableMappingTest.php b/tests/Gedmo/Mapping/UploadableMappingTest.php index 79624146b8..fb60c483dd 100644 --- a/tests/Gedmo/Mapping/UploadableMappingTest.php +++ b/tests/Gedmo/Mapping/UploadableMappingTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Tests\Mapping\Fixture\Uploadable as AnnotatedUploadable; @@ -53,7 +52,7 @@ public static function dataUploadableObject(): \Generator { yield 'Model with XML mapping' => [XmlUploadable::class]; - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (PHP_VERSION_ID >= 80000) { yield 'Model with attributes' => [AnnotatedUploadable::class]; } diff --git a/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php b/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php index 58075d0cc7..1c65cd7655 100644 --- a/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php @@ -15,6 +15,7 @@ use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\Tests\Mapping\Fixture\ClosureTreeClosure; @@ -37,8 +38,11 @@ protected function setUp(): void { parent::setUp(); - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); + if (PHP_VERSION_ID >= 80000) { + $annotationDriver = new AttributeDriver([]); + } else { + $annotationDriver = new AnnotationDriver(new AnnotationReader()); + } $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); diff --git a/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php b/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php index bce2f8af90..e728143bae 100644 --- a/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php @@ -15,6 +15,7 @@ use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\Tests\Mapping\Fixture\Xml\MaterializedPathTree; @@ -37,8 +38,11 @@ protected function setUp(): void { parent::setUp(); - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); + if (PHP_VERSION_ID >= 80000) { + $annotationDriver = new AttributeDriver([]); + } else { + $annotationDriver = new AnnotationDriver(new AnnotationReader()); + } $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); diff --git a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php index ce374f6bb7..3cf3ee0b03 100644 --- a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php @@ -15,6 +15,7 @@ use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\References\ReferencesListener; @@ -34,8 +35,11 @@ protected function setUp(): void { parent::setUp(); - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); + if (PHP_VERSION_ID >= 80000) { + $annotationDriver = new AttributeDriver([]); + } else { + $annotationDriver = new AnnotationDriver(new AnnotationReader()); + } $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); diff --git a/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php b/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php index 31b77eb11e..f2dba6f3e3 100644 --- a/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php @@ -15,6 +15,7 @@ use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\Tests\Mapping\Fixture\Xml\Translatable; @@ -38,8 +39,11 @@ protected function setUp(): void { parent::setUp(); - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); + if (PHP_VERSION_ID >= 80000) { + $annotationDriver = new AttributeDriver([]); + } else { + $annotationDriver = new AnnotationDriver(new AnnotationReader()); + } $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml'); diff --git a/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php b/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php index 140e7aba0c..b65364aa15 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php @@ -11,23 +11,53 @@ namespace Gedmo\Tests\Sluggable\Fixture\Issue116; +use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation as Gedmo; + +/** + * @ORM\Entity + * @ORM\Table(name="sta_country") + */ +#[ORM\Entity] +#[ORM\Table(name: 'sta_country')] class Country { /** * @var int|null + * + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] private $id; /** * @var string|null + * + * @ORM\Column(type="string", length=10, nullable=true) */ + #[ORM\Column(type: Types::STRING, length: 10, nullable: true)] private $languageCode; + /** + * @ORM\Column(type="string", length=50) + */ + #[ORM\Column(type: Types::STRING, length: 50)] private ?string $originalName = null; /** * @var string|null + * + * @ORM\Column(type="string", length=50) + * + * @Gedmo\Slug(separator="-", fields={"originalName"}) */ + #[ORM\Column(type: Types::STRING, length: 50)] + #[Gedmo\Slug(separator: '-', fields: ['originalName'])] private $alias; public function getId(): ?int diff --git a/tests/Gedmo/Sluggable/Issue/Issue116Test.php b/tests/Gedmo/Sluggable/Issue/Issue116Test.php index 7125ba1e15..3a95f683f7 100644 --- a/tests/Gedmo/Sluggable/Issue/Issue116Test.php +++ b/tests/Gedmo/Sluggable/Issue/Issue116Test.php @@ -12,6 +12,7 @@ namespace Gedmo\Tests\Sluggable\Issue; use Doctrine\Common\EventManager; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -52,10 +53,15 @@ public function testSlugGeneration(): void protected function getMetadataDriverImplementation(): MappingDriver { $chain = new MappingDriverChain(); - $chain->addDriver( - new YamlDriver([__DIR__.'/../Fixture/Issue116/Mapping']), - 'Gedmo\Tests\Sluggable\Fixture\Issue116' - ); + + if (PHP_VERSION_ID >= 80000) { + $chain->addDriver(new AttributeDriver([]), 'Gedmo\Tests\Sluggable\Fixture\Issue116'); + } else { + $chain->addDriver( + new YamlDriver([__DIR__.'/../Fixture/Issue116/Mapping']), + 'Gedmo\Tests\Sluggable\Fixture\Issue116' + ); + } return $chain; }