Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject an attribute metadata driver into the DoctrineDriver when testing #1520

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions tests/Metadata/Driver/DoctrineDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand All @@ -167,7 +181,7 @@ protected function getDoctrineDriver()
->will($this->returnValue($this->getEntityManager()));

return new DoctrineTypeDriver(
$this->getAnnotationDriver(),
$this->getMetadataDriver(),
$registry
);
}
Expand Down
Loading