Skip to content

Commit

Permalink
Merge pull request #1297 from ergebnis/fix/entity-manager
Browse files Browse the repository at this point in the history
Fix: Do not use deprecated `Doctrine\ORM\EntityManager::create()`
  • Loading branch information
localheinz authored Feb 7, 2024
2 parents c9b76d6 + 1a838f0 commit 1c72dcc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 48 deletions.
13 changes: 8 additions & 5 deletions example/test/Unit/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Example\Test\Unit;

use Doctrine\DBAL;
use Doctrine\ORM;
use Ergebnis\FactoryBot;
use Faker\Factory;
Expand All @@ -23,17 +24,19 @@ abstract class AbstractTestCase extends Framework\TestCase
{
final protected static function entityManager(): ORM\EntityManagerInterface
{
$connection = DBAL\DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'path' => ':memory:',
]);

$configuration = ORM\ORMSetup::createConfiguration(true);

$configuration->setMetadataDriverImpl(new ORM\Mapping\Driver\AttributeDriver([
__DIR__ . '/../../src/Entity',
]));

$entityManager = ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
$entityManager = new ORM\EntityManager(
$connection,
$configuration,
);

Expand Down
16 changes: 0 additions & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ parameters:
count: 1
path: example/test/AutoReview/FixtureTest.php

-
message: """
#^Call to deprecated method create\\(\\) of class Doctrine\\\\ORM\\\\EntityManager\\:
Use \\{@see DriverManager\\:\\:getConnection\\(\\)\\} to bootstrap the connection and call the constructor\\.$#
"""
count: 1
path: example/test/Unit/AbstractTestCase.php

-
message: "#^Instanceof between Ergebnis\\\\FactoryBot\\\\FieldDefinition\\\\Resolvable and Ergebnis\\\\FactoryBot\\\\FieldDefinition\\\\Resolvable will always evaluate to true\\.$#"
count: 1
Expand Down Expand Up @@ -551,11 +543,3 @@ parameters:
count: 1
path: test/Unit/FixtureFactoryTest.php

-
message: """
#^Call to deprecated method create\\(\\) of class Doctrine\\\\ORM\\\\EntityManager\\:
Use \\{@see DriverManager\\:\\:getConnection\\(\\)\\} to bootstrap the connection and call the constructor\\.$#
"""
count: 1
path: test/Util/Doctrine/ORM/EntityManagerFactory.php

22 changes: 0 additions & 22 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@
<code>ProjectDefinitionProvider</code>
</UnusedClass>
</file>
<file src="example/test/Unit/AbstractTestCase.php">
<DeprecatedMethod>
<code><![CDATA[ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
$configuration,
)]]></code>
</DeprecatedMethod>
</file>
<file src="example/test/Unit/Entity/UserTest.php">
<UnnecessaryVarAnnotation>
<code>Entity\User</code>
Expand Down Expand Up @@ -444,15 +433,4 @@
<code>$resolved</code>
</MixedAssignment>
</file>
<file src="test/Util/Doctrine/ORM/EntityManagerFactory.php">
<DeprecatedMethod>
<code><![CDATA[ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
$configuration,
)]]></code>
</DeprecatedMethod>
</file>
</files>
13 changes: 8 additions & 5 deletions test/Util/Doctrine/ORM/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@

namespace Ergebnis\FactoryBot\Test\Util\Doctrine\ORM;

use Doctrine\DBAL;
use Doctrine\ORM;

final class EntityManagerFactory
{
public static function create(): ORM\EntityManagerInterface
{
$connection = DBAL\DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'path' => ':memory:',
]);

$configuration = ORM\ORMSetup::createConfiguration(true);

$configuration->setMetadataDriverImpl(new ORM\Mapping\Driver\AttributeDriver([
__DIR__ . '/../../../../example/src/Entity',
]));

return ORM\EntityManager::create(
[
'driver' => 'pdo_sqlite',
'path' => ':memory:',
],
return new ORM\EntityManager(
$connection,
$configuration,
);
}
Expand Down

0 comments on commit 1c72dcc

Please sign in to comment.