diff --git a/tests/Metadata/Driver/DoctrineDriverTest.php b/tests/Metadata/Driver/DoctrineDriverTest.php index 6f25c0bc1..4fe357754 100644 --- a/tests/Metadata/Driver/DoctrineDriverTest.php +++ b/tests/Metadata/Driver/DoctrineDriverTest.php @@ -12,9 +12,12 @@ use Doctrine\ORM\Version as ORMVersion; use Doctrine\Persistence\ManagerRegistry; use JMS\Serializer\Metadata\Driver\AnnotationDriver; +use JMS\Serializer\Metadata\Driver\AnnotationOrAttributeDriver; use JMS\Serializer\Metadata\Driver\DoctrineTypeDriver; +use JMS\Serializer\Metadata\Driver\NullDriver; use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy; use JMS\Serializer\Tests\Fixtures\Doctrine\Embeddable\BlogPostWithEmbedded; +use Metadata\Driver\DriverChain; use PHPUnit\Framework\TestCase; class DoctrineDriverTest extends TestCase @@ -94,7 +97,7 @@ public function testNonDoctrineEntityClassIsNotModified() // because it has no Doctrine metadata. $refClass = new \ReflectionClass('JMS\Serializer\Tests\Fixtures\BlogPost'); - $plainMetadata = $this->getAnnotationDriver()->loadMetadataForClass($refClass); + $plainMetadata = $this->getMetadataDriver()->loadMetadataForClass($refClass); $doctrineMetadata = $this->getDoctrineDriver()->loadMetadataForClass($refClass); // Do not compare timestamps @@ -107,7 +110,7 @@ public function testNonDoctrineEntityClassIsNotModified() public function testExcludePropertyNoPublicAccessorException() { - $first = $this->getAnnotationDriver() + $first = $this->getMetadataDriver() ->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\ExcludePublicAccessor')); self::assertArrayHasKey('id', $first->propertyMetadata); @@ -154,9 +157,20 @@ protected function getEntityManager() return EntityManager::create($conn, $config); } - public function getAnnotationDriver() + public function getMetadataDriver() { - return new AnnotationDriver(new AnnotationReader(), new IdenticalPropertyNamingStrategy()); + $driver = new DriverChain(); + $namingStrategy = new IdenticalPropertyNamingStrategy(); + + if (PHP_VERSION_ID >= 80000) { + $driver->addDriver(new AnnotationOrAttributeDriver($namingStrategy)); + } else { + $driver->addDriver(new AnnotationDriver(new AnnotationReader(), $namingStrategy)); + } + + $driver->addDriver(new NullDriver($namingStrategy)); + + return $driver; } protected function getDoctrineDriver() @@ -167,7 +181,7 @@ protected function getDoctrineDriver() ->will($this->returnValue($this->getEntityManager())); return new DoctrineTypeDriver( - $this->getAnnotationDriver(), + $this->getMetadataDriver(), $registry ); }