Skip to content

Commit

Permalink
Update Doctrine utility to Doctrine 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryszon committed Jun 13, 2024
1 parent 0abdc85 commit fc9b1d2
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Reun/TestUtilities/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,31 @@

namespace Reun\TestUtilities;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\DBAL\Logging\EchoSQLLogger;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\Setup;

class Doctrine
{
public static function createEntityManager(
array $withSchemaClasses = [],
array $connection = ["url" => "sqlite:///:memory:"],
array $connection = [
"driver" => "sqlite3",
"memory" => true,
],
array $paths = ["../../../src/"],
bool $recreateSchema = true,
bool $logging = false
): EntityManagerInterface {
// Initialize AnnotationRegistry loader
AnnotationRegistry::registerLoader("class_exists");
$connection = DriverManager::getConnection($connection);

$paths = ["../../../src/"];
$config = Setup::createAnnotationMetadataConfiguration(
$doctrineConfig = ORMSetup::createAttributeMetadataConfiguration(
$paths,
true,
null,
null,
false
true
);
$logging && $config->setSQLLogger(new EchoSQLLogger());

$em = EntityManager::create($connection, $config);
$em = new EntityManager($connection, $doctrineConfig);

if ($withSchemaClasses) {
$schemaTool = new SchemaTool($em);
Expand Down

0 comments on commit fc9b1d2

Please sign in to comment.