Skip to content

Commit dc484a3

Browse files
authored
Merge pull request #1520 from mbabker/test-doctrine-driver-with-attribute-driver
Inject an attribute metadata driver into the DoctrineDriver when testing
2 parents 9c2ac39 + 660a986 commit dc484a3

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

tests/Metadata/Driver/DoctrineDriverTest.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
use Doctrine\ORM\Version as ORMVersion;
1313
use Doctrine\Persistence\ManagerRegistry;
1414
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
15+
use JMS\Serializer\Metadata\Driver\AnnotationOrAttributeDriver;
1516
use JMS\Serializer\Metadata\Driver\DoctrineTypeDriver;
17+
use JMS\Serializer\Metadata\Driver\NullDriver;
1618
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
1719
use JMS\Serializer\Tests\Fixtures\Doctrine\Embeddable\BlogPostWithEmbedded;
20+
use Metadata\Driver\DriverChain;
1821
use PHPUnit\Framework\TestCase;
1922

2023
class DoctrineDriverTest extends TestCase
@@ -94,7 +97,7 @@ public function testNonDoctrineEntityClassIsNotModified()
9497
// because it has no Doctrine metadata.
9598
$refClass = new \ReflectionClass('JMS\Serializer\Tests\Fixtures\BlogPost');
9699

97-
$plainMetadata = $this->getAnnotationDriver()->loadMetadataForClass($refClass);
100+
$plainMetadata = $this->getMetadataDriver()->loadMetadataForClass($refClass);
98101
$doctrineMetadata = $this->getDoctrineDriver()->loadMetadataForClass($refClass);
99102

100103
// Do not compare timestamps
@@ -107,7 +110,7 @@ public function testNonDoctrineEntityClassIsNotModified()
107110

108111
public function testExcludePropertyNoPublicAccessorException()
109112
{
110-
$first = $this->getAnnotationDriver()
113+
$first = $this->getMetadataDriver()
111114
->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\ExcludePublicAccessor'));
112115

113116
self::assertArrayHasKey('id', $first->propertyMetadata);
@@ -154,9 +157,20 @@ protected function getEntityManager()
154157
return EntityManager::create($conn, $config);
155158
}
156159

157-
public function getAnnotationDriver()
160+
public function getMetadataDriver()
158161
{
159-
return new AnnotationDriver(new AnnotationReader(), new IdenticalPropertyNamingStrategy());
162+
$driver = new DriverChain();
163+
$namingStrategy = new IdenticalPropertyNamingStrategy();
164+
165+
if (PHP_VERSION_ID >= 80000) {
166+
$driver->addDriver(new AnnotationOrAttributeDriver($namingStrategy));
167+
} else {
168+
$driver->addDriver(new AnnotationDriver(new AnnotationReader(), $namingStrategy));
169+
}
170+
171+
$driver->addDriver(new NullDriver($namingStrategy));
172+
173+
return $driver;
160174
}
161175

162176
protected function getDoctrineDriver()
@@ -167,7 +181,7 @@ protected function getDoctrineDriver()
167181
->will($this->returnValue($this->getEntityManager()));
168182

169183
return new DoctrineTypeDriver(
170-
$this->getAnnotationDriver(),
184+
$this->getMetadataDriver(),
171185
$registry
172186
);
173187
}

0 commit comments

Comments
 (0)