Skip to content

Commit

Permalink
fix EntityManager::create deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
DubbleClick authored and franmomu committed Sep 8, 2023
1 parent 4010c0c commit 512695c
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"doctrine/dbal": "^2.13.1 || ^3.2",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/mongodb-odm": "^2.3",
"doctrine/orm": "^2.10.2",
"doctrine/orm": "^2.14.0",
"friendsofphp/php-cs-fixer": "^3.4.0 <3.10",
"nesbot/carbon": "^2.55",
"phpstan/phpstan": "^1.10.2",
Expand Down
5 changes: 3 additions & 2 deletions doc/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ $evm->addEventSubscriber($sortableListener);
// mysql set names UTF-8 if required
$evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());
// DBAL connection
$connection = array(
$driverParams = array(
'driver' => 'pdo_mysql',
'host' => '127.0.0.1',
'dbname' => 'test',
'user' => 'root',
'password' => ''
);
// Finally, create entity manager
$em = Doctrine\ORM\EntityManager::create($connection, $config, $evm);
$connection = DriverManager::getConnection($driverParams, $config);
$em = new EntityManager($connection, $config, $evm);
```

**Note:** that Symfony StofDoctrineExtensionsBundle does it automatically this
Expand Down
4 changes: 3 additions & 1 deletion example/em.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
Expand Down Expand Up @@ -154,4 +155,5 @@
$config->setResultCache($cache);

// Finally, we create the entity manager
return EntityManager::create($connection, $config, $eventManager);
$connection = DriverManager::getConnection($connection, $config);
$em = new EntityManager($connection, $config, $eventManager);
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/LoggableORMMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\YamlDriver;
Expand Down Expand Up @@ -66,7 +67,8 @@ protected function setUp(): void
$loggableListener = new LoggableListener();
$loggableListener->setCacheItemPool($this->cache);
$evm->addEventSubscriber($loggableListener);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
}

public function testLoggableMapping(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/MappingEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
Expand Down Expand Up @@ -44,7 +45,8 @@ protected function setUp(): void
'memory' => true,
];

$this->em = EntityManager::create($conn, $config, new EventManager());
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, new EventManager());
}

public function testGetMetadataFactoryCacheFromDoctrineForSluggable(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Gedmo\Tests\Mapping\MetadataFactory;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -55,7 +56,8 @@ protected function setUp(): void
$this->timestampable = new TimestampableListener();
$this->timestampable->setAnnotationReader($_ENV['annotation_reader']);
$evm->addEventSubscriber($this->timestampable);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);

$schemaTool = new SchemaTool($this->em);
$schemaTool->dropSchema([]);
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Gedmo\Tests\Mapping\MetadataFactory;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -60,7 +61,8 @@ protected function setUp(): void
$this->timestampable = new TimestampableListener();
$this->timestampable->setAnnotationReader($_ENV['annotation_reader']);
$evm->addEventSubscriber($this->timestampable);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
}

public function testShouldWork(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/SluggableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\YamlDriver;
Expand Down Expand Up @@ -65,7 +66,8 @@ protected function setUp(): void
$listener = new SluggableListener();
$listener->setCacheItemPool($this->cache);
$evm->addEventSubscriber($listener);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
}

public function testShouldBeAbleToMapSluggableUsingYamlDriver(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/TimestampableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Gedmo\Tests\Mapping;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\YamlDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
Expand Down Expand Up @@ -54,7 +55,8 @@ protected function setUp(): void
$listener = new TimestampableListener();
$listener->setCacheItemPool($this->cache);
$evm->addEventSubscriber($listener);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
}

public function testYamlMapping(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/TranslatableMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Gedmo\Tests\Mapping;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\YamlDriver;
Expand Down Expand Up @@ -62,7 +63,8 @@ protected function setUp(): void
$this->translatableListener->setCacheItemPool($this->cache);
$this->translatableListener->setTranslatableLocale('en_us');
$evm->addEventSubscriber($this->translatableListener);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
}

public function testYamlMapping(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Mapping/TreeMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Gedmo\Tests\Mapping;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\YamlDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
Expand Down Expand Up @@ -72,7 +73,8 @@ protected function setUp(): void
$this->listener->setCacheItemPool($this->cache);
$evm = new EventManager();
$evm->addEventSubscriber($this->listener);
$this->em = EntityManager::create($conn, $config, $evm);
$connection = DriverManager::getConnection($conn, $config);
$this->em = new EntityManager($connection, $config, $evm);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/Gedmo/Tool/BaseTestCaseOM.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
namespace Gedmo\Tests\Tool;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver as AnnotationDriverODM;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver as AnnotationDriverORM;
use Doctrine\ORM\Mapping\Driver\AttributeDriver as AttributeDriverORM;
use Doctrine\ORM\Repository\DefaultRepositoryFactory as DefaultRepositoryFactoryORM;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Gedmo\Loggable\LoggableListener;
use Gedmo\Sluggable\SluggableListener;
Expand Down Expand Up @@ -128,7 +129,8 @@ protected function getDefaultMockSqliteEntityManager(array $fixtures, ?MappingDr
];

$config = $this->getMockORMConfig($mappingDriver);
$em = EntityManager::create($conn, $config, $this->getEventManager());
$connection = DriverManager::getConnection($conn, $config);
$em = new EntityManager($connection, $config, $this->getEventManager());

$schema = array_map(static function (string $class) use ($em): ClassMetadata {
assert(class_exists($class));
Expand Down
4 changes: 3 additions & 1 deletion tests/Gedmo/Tool/BaseTestCaseORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Logging\Middleware;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
Expand Down Expand Up @@ -73,7 +74,8 @@ protected function getDefaultMockSqliteEntityManager(?EventManager $evm = null,
];

$config = $config ?? $this->getDefaultConfiguration();
$em = EntityManager::create($conn, $config, $evm ?? $this->getEventManager());
$connection = DriverManager::getConnection($conn, $config);
$em = new EntityManager($connection, $config, $evm ?? $this->getEventManager());

$schema = array_map(static function (string $class) use ($em): ClassMetadata {
return $em->getClassMetadata($class);
Expand Down

0 comments on commit 512695c

Please sign in to comment.