Skip to content

Commit

Permalink
Merge pull request #1095 from ostrolucky/doctrine-deprecations
Browse files Browse the repository at this point in the history
Fix doctrine deprecations
  • Loading branch information
alcaeus committed Dec 17, 2019
2 parents 42feae2 + 90bfea9 commit b612f15
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\EntityGenerator;
use Doctrine\Persistence\ManagerRegistry;
use LogicException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down
2 changes: 1 addition & 1 deletion Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
use Doctrine\ORM\Tools\Console\MetadataFilter;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use Doctrine\Persistence\ManagerRegistry;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down
9 changes: 0 additions & 9 deletions Command/Proxy/DelegateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;

use Doctrine\ORM\Version;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -30,14 +29,6 @@ protected function getMinimalVersion()
return '2.3.0-DEV';
}

/**
* @return bool
*/
private function isVersionCompatible()
{
return version_compare(Version::VERSION, $this->getMinimalVersion()) >= 0;
}

/**
* {@inheritDoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion DataCollector/DoctrineDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Doctrine\Bundle\DoctrineBundle\DataCollector;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Cache\Logging\CacheLoggerChain;
use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector as BaseCollector;
use Symfony\Component\HttpFoundation\Request;
Expand Down
11 changes: 6 additions & 5 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Version;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use LogicException;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
Expand Down Expand Up @@ -93,8 +93,9 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$loader->load('dbal.xml');

if (method_exists(Alias::class, 'setDeprecated')) {
$container->getAlias('Symfony\Bridge\Doctrine\RegistryInterface')->setDeprecated(true, 'The "%alias_id%" service alias is deprecated, use `Doctrine\Common\Persistence\ManagerRegistry` instead.');
$container->getAlias('Doctrine\Bundle\DoctrineBundle\Registry')->setDeprecated(true, 'The "%alias_id%" service alias is deprecated, use `Doctrine\Common\Persistence\ManagerRegistry` instead.');
$container->getAlias('Symfony\Bridge\Doctrine\RegistryInterface')->setDeprecated(true, 'The "%alias_id%" service alias is deprecated, use `Doctrine\Persistence\ManagerRegistry` instead.');
$container->getAlias('Doctrine\Bundle\DoctrineBundle\Registry')->setDeprecated(true, 'The "%alias_id%" service alias is deprecated, use `Doctrine\Persistence\ManagerRegistry` instead.');
$container->getAlias('Doctrine\Common\Persistence\ManagerRegistry')->setDeprecated(true, 'The "%alias_id%" service alias is deprecated, use `Doctrine\Persistence\ManagerRegistry` instead.');
}

if (empty($config['default_connection'])) {
Expand Down Expand Up @@ -346,7 +347,7 @@ protected function getConnectionOptions($connection)
*/
protected function ormLoad(array $config, ContainerBuilder $container)
{
if (! class_exists(Version::class)) {
if (! class_exists(UnitOfWork::class)) {
throw new LogicException('To configure the ORM layer, you must first install the doctrine/orm package.');
}

Expand Down
2 changes: 1 addition & 1 deletion Mapping/DisconnectedMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Doctrine\Bundle\DoctrineBundle\Mapping;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Doctrine\Persistence\ManagerRegistry;
use ReflectionClass;
use RuntimeException;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
Expand Down
2 changes: 1 addition & 1 deletion Repository/ContainerRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Doctrine\Bundle\DoctrineBundle\Repository;

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Repository\RepositoryFactory;
use Doctrine\Persistence\ObjectRepository;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use RuntimeException;
Expand Down
2 changes: 1 addition & 1 deletion Repository/ServiceEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Doctrine\Bundle\DoctrineBundle\Repository;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use LogicException;

/**
Expand Down
1 change: 1 addition & 0 deletions Resources/config/dbal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<argument>%doctrine.default_connection%</argument>
<argument>%doctrine.default_entity_manager%</argument>
</service>
<service id="Doctrine\Persistence\ManagerRegistry" alias="doctrine" public="false" />
<service id="Doctrine\Common\Persistence\ManagerRegistry" alias="doctrine" public="false" />
<service id="Symfony\Bridge\Doctrine\RegistryInterface" alias="doctrine" public="false" />
<service id="Doctrine\Bundle\DoctrineBundle\Registry" alias="doctrine" public="false" />
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/CreateDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testExecuteWithShardOption()
private function getMockContainer($connectionName, $params = null)
{
// Mock the container and everything you'll need here
$mockDoctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
$mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')
->getMock();

$mockDoctrine->expects($this->any())
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/DropDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testExecuteWithoutOptionForceWillFailWithAttentionMessage()
private function getMockContainer($connectionName, $params = null)
{
// Mock the container and everything you'll need here
$mockDoctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
$mockDoctrine = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')
->getMock();

$mockDoctrine->expects($this->any())
Expand Down
12 changes: 0 additions & 12 deletions Tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,10 @@
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\ORM\Version;
use Exception;

class ConnectionFactoryTest extends TestCase
{
protected function setUp()
{
parent::setUp();

if (class_exists(Version::class)) {
return;
}

$this->markTestSkipped('Doctrine ORM is not available.');
}

/**
* @expectedException \Doctrine\DBAL\DBALException
*/
Expand Down
23 changes: 8 additions & 15 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\EventManager;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\DBAL\Configuration as DBALConfiguration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Version;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
use Symfony\Bridge\Doctrine\Logger\DbalLogger;
Expand All @@ -24,17 +23,11 @@

class ContainerTest extends TestCase
{
protected function setUp()
{
parent::setUp();

if (class_exists(Version::class)) {
return;
}

$this->markTestSkipped('Doctrine ORM is not available.');
}

/**
* https://github.com/doctrine/orm/pull/7953 needed, otherwise ORM classes we define services for trigger deprecations
*
* @group legacy
*/
public function testContainer()
{
$container = $this->createXmlBundleTestContainer();
Expand Down
2 changes: 1 addition & 1 deletion Tests/DataCollector/DoctrineDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function createEntityMetadata($entityFQCN)
*/
private function createCollector(array $managers)
{
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock();
$registry
->expects($this->any())
->method('getConnectionNames')
Expand Down
16 changes: 11 additions & 5 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\Bundle\DoctrineBundle\Tests\Builder\BundleConfigurationBuilder;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\Common\Persistence\ManagerRegistry as DeprecatedManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager as DeprecatedObjectManager;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
Expand All @@ -23,6 +23,11 @@

class DoctrineExtensionTest extends TestCase
{
/**
* https://github.com/doctrine/orm/pull/7953 needed, otherwise ORM classes we define services for trigger deprecations
*
* @group legacy
*/
public function testAutowiringAlias()
{
$container = $this->getContainer();
Expand All @@ -34,8 +39,9 @@ public function testAutowiringAlias()
$expectedAliases = [
DriverConnection::class => 'database_connection',
Connection::class => 'database_connection',
DeprecatedManagerRegistry::class => 'doctrine',
DeprecatedObjectManager::class => 'doctrine.orm.entity_manager',
ManagerRegistry::class => 'doctrine',
ObjectManager::class => 'doctrine.orm.entity_manager',
EntityManagerInterface::class => 'doctrine.orm.entity_manager',
];

Expand Down Expand Up @@ -385,7 +391,7 @@ public function testAutoGenerateProxyClasses()

$extension->load([$config], $container);

$this->assertEquals(AbstractProxyFactory::AUTOGENERATE_EVAL, $container->getParameter('doctrine.orm.auto_generate_proxy_classes'));
$this->assertEquals(3 /* \Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_EVAL */, $container->getParameter('doctrine.orm.auto_generate_proxy_classes'));
}

public function testSingleEntityManagerWithDefaultConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Fixtures\Bundles\RepositoryServiceBundle\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomServiceRepoEntity;

class TestCustomServiceRepoRepository extends ServiceEntityRepository
Expand Down
16 changes: 2 additions & 14 deletions Tests/Mapping/DisconnectedMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Version;

class DisconnectedMetadataFactoryTest extends TestCase
{
protected function setUp()
{
parent::setUp();

if (class_exists(Version::class)) {
return;
}

$this->markTestSkipped('Doctrine ORM is not available.');
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Can't find base path for "Doctrine\Bundle\DoctrineBundle\Tests\Mapping\DisconnectedMetadataFactoryTest
Expand All @@ -30,7 +18,7 @@ public function testCannotFindNamespaceAndPathForMetadata()
$class = new ClassMetadataInfo(self::class);
$collection = new ClassMetadataCollection([$class]);

$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock();
$factory = new DisconnectedMetadataFactory($registry);

$factory->findNamespaceAndPathForMetadata($collection);
Expand All @@ -41,7 +29,7 @@ public function testFindNamespaceAndPathForMetadata()
$class = new ClassMetadataInfo('\Vendor\Package\Class');
$collection = new ClassMetadataCollection([$class]);

$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder('Doctrine\Persistence\ManagerRegistry')->getMock();
$factory = new DisconnectedMetadataFactory($registry);

$factory->findNamespaceAndPathForMetadata($collection, '/path/to/code');
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector;
use Doctrine\Bundle\DoctrineBundle\Twig\DoctrineExtension;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Symfony\Bridge\Twig\Extension\CodeExtension;
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
Expand Down

0 comments on commit b612f15

Please sign in to comment.