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

Allow doctrine/persistence v2/v3 #1210

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ matrix:

- php: 7.3
- php: 7.4

- php: 7.4
env: VERY_LATEST=1
fast_finish: true

install:
Expand Down
2 changes: 2 additions & 0 deletions .travis/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ composer self-update

if [[ $TRAVIS_PHP_VERSION != '7.2' ]]; then phpenv config-rm xdebug.ini || true; fi

if [[ $VERY_LATEST == '1' ]]; then composer remove --dev doctrine/phpcr-odm --no-update -n; fi

composer update $COMPOSER_FLAGS -n
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"symfony/filesystem": "^3.0|^4.0|^5.0",
"symfony/expression-language": "^3.0|^4.0|^5.0",
"phpunit/phpunit": "^8.0||^9.0",
"doctrine/coding-standard": "^5.0"
"doctrine/coding-standard": "^5.0",
"doctrine/persistence": "^1.3.3|^2.0|^3.0"
},
"conflict": {
"hoa/core": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/Construction/DoctrineObjectConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Construction;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\Exception\InvalidArgumentException;
use JMS\Serializer\Exception\ObjectConstructionException;
Expand Down
5 changes: 4 additions & 1 deletion src/EventDispatcher/Subscriber/DoctrineProxySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace JMS\Serializer\EventDispatcher\Subscriber;

use Doctrine\Common\Persistence\Proxy;
use Doctrine\Common\Persistence\Proxy as LegacyProxy;
use Doctrine\ODM\MongoDB\PersistentCollection as MongoDBPersistentCollection;
use Doctrine\ODM\PHPCR\PersistentCollection as PHPCRPersistentCollection;
use Doctrine\ORM\PersistentCollection;
use Doctrine\Persistence\Proxy;
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\PreSerializeEvent;
Expand Down Expand Up @@ -111,10 +112,12 @@ public static function getSubscribedEvents()
{
return [
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerializeTypedProxy', 'interface' => Proxy::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerializeTypedProxy', 'interface' => LegacyProxy::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerialize', 'interface' => PersistentCollection::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerialize', 'interface' => MongoDBPersistentCollection::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerialize', 'interface' => PHPCRPersistentCollection::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerialize', 'interface' => Proxy::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerialize', 'interface' => LegacyProxy::class],
['event' => 'serializer.pre_serialize', 'method' => 'onPreSerialize', 'interface' => LazyLoadingInterface::class],
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Metadata/Driver/AbstractDoctrineTypeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace JMS\Serializer\Metadata\Driver;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata as DoctrineClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\ClassMetadata as DoctrineClassMetadata;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\Metadata\ExpressionPropertyMetadata;
use JMS\Serializer\Metadata\PropertyMetadata;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Driver/DoctrinePHPCRTypeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Metadata\Driver;

use Doctrine\Common\Persistence\Mapping\ClassMetadata as DoctrineClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadata as DoctrineClassMetadata;
use JMS\Serializer\Metadata\PropertyMetadata;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Driver/DoctrineTypeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Metadata\Driver;

use Doctrine\Common\Persistence\Mapping\ClassMetadata as DoctrineClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadata as DoctrineClassMetadata;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\Metadata\PropertyMetadata;

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/SimpleObjectProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Tests\Fixtures;

use Doctrine\Common\Persistence\Proxy;
use Doctrine\Persistence\Proxy;

class SimpleObjectProxy extends SimpleObject implements Proxy
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Metadata/Driver/DoctrineDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver as DoctrineDriver;
use Doctrine\ORM\Version as ORMVersion;
use Doctrine\Persistence\ManagerRegistry;
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
use JMS\Serializer\Metadata\Driver\DoctrineTypeDriver;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
Expand Down Expand Up @@ -151,7 +152,7 @@ public function getAnnotationDriver()

protected function getDoctrineDriver()
{
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry->expects($this->atLeastOnce())
->method('getManagerForClass')
->will($this->returnValue($this->getEntityManager()));
Expand Down
9 changes: 8 additions & 1 deletion tests/Metadata/Driver/DoctrinePHPCRDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
use Doctrine\ODM\PHPCR\Configuration;
use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver as DoctrinePHPCRDriver;
use Doctrine\Persistence\ManagerRegistry;
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
use JMS\Serializer\Metadata\Driver\DoctrinePHPCRTypeDriver;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use PHPUnit\Framework\TestCase;

class DoctrinePHPCRDriverTest extends TestCase
{
protected function setUp(): void
{
if (!class_exists(Configuration::class)) {
$this->markTestSkipped('PHPCR not available');
}
}
public function getMetadata()
{
$refClass = new \ReflectionClass('JMS\Serializer\Tests\Fixtures\DoctrinePHPCR\BlogPost');
Expand Down Expand Up @@ -103,7 +110,7 @@ public function getAnnotationDriver()

protected function getDoctrinePHPCRDriver()
{
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry->expects($this->atLeastOnce())
->method('getManagerForClass')
->will($this->returnValue($this->getDocumentManager()));
Expand Down
8 changes: 4 additions & 4 deletions tests/Serializer/Doctrine/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\AbstractManagerRegistry;
use Doctrine\Persistence\Proxy;
use JMS\Serializer\Builder\CallbackDriverFactory;
use JMS\Serializer\Builder\DefaultDriverFactory;
use JMS\Serializer\Metadata\Driver\DoctrineTypeDriver;
Expand All @@ -31,7 +31,7 @@

class IntegrationTest extends TestCase
{
/** @var ManagerRegistry */
/** @var AbstractManagerRegistry */
private $registry;

/** @var Serializer */
Expand Down Expand Up @@ -150,7 +150,7 @@ class SimpleManagerRegistry extends AbstractManagerRegistry
private $services = [];
private $serviceCreator;

public function __construct($serviceCreator, $name = 'anonymous', array $connections = ['default' => 'default_connection'], array $managers = ['default' => 'default_manager'], $defaultConnection = null, $defaultManager = null, $proxyInterface = 'Doctrine\Common\Persistence\Proxy')
public function __construct($serviceCreator, $name = 'anonymous', array $connections = ['default' => 'default_connection'], array $managers = ['default' => 'default_manager'], $defaultConnection = null, $defaultManager = null, $proxyInterface = Proxy::class)
{
if (null === $defaultConnection) {
$defaultConnection = key($connections);
Expand Down
8 changes: 4 additions & 4 deletions tests/Serializer/Doctrine/ObjectConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\Type;
Expand All @@ -19,6 +17,8 @@
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\UnitOfWork;
use Doctrine\ORM\Version as ORMVersion;
use Doctrine\Persistence\AbstractManagerRegistry;
use Doctrine\Persistence\Proxy;
use JMS\Serializer\Builder\CallbackDriverFactory;
use JMS\Serializer\Builder\DefaultDriverFactory;
use JMS\Serializer\Construction\DoctrineObjectConstructor;
Expand All @@ -42,7 +42,7 @@

class ObjectConstructorTest extends TestCase
{
/** @var ManagerRegistry */
/** @var AbstractManagerRegistry */
private $registry;

/** @var Serializer */
Expand Down Expand Up @@ -362,7 +362,7 @@ class SimpleBaseManagerRegistry extends AbstractManagerRegistry
private $services = [];
private $serviceCreator;

public function __construct($serviceCreator, $name = 'anonymous', array $connections = ['default' => 'default_connection'], array $managers = ['default' => 'default_manager'], $defaultConnection = null, $defaultManager = null, $proxyInterface = 'Doctrine\Common\Persistence\Proxy')
public function __construct($serviceCreator, $name = 'anonymous', array $connections = ['default' => 'default_connection'], array $managers = ['default' => 'default_manager'], $defaultConnection = null, $defaultManager = null, $proxyInterface = Proxy::class)
{
if (null === $defaultConnection) {
$defaultConnection = key($connections);
Expand Down
2 changes: 1 addition & 1 deletion tests/Serializer/EventDispatcher/EventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JMS\Serializer\Tests\Serializer\EventDispatcher;

use Doctrine\Common\Persistence\Proxy;
use Doctrine\Persistence\Proxy;
use JMS\Serializer\Context;
use JMS\Serializer\EventDispatcher\Event;
use JMS\Serializer\EventDispatcher\EventDispatcher;
Expand Down