Completed
Pull Request — master (#10)
by Gabriel
60:20
created

TestAddressChangeContextFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityManager() 0 13 2
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests;
6
7
use Doctrine\Common\Annotations\AnnotationRegistry;
8
use Doctrine\DBAL\Connection;
9
use Doctrine\DBAL\DriverManager;
10
use Doctrine\ORM\Configuration;
11
use Doctrine\ORM\EntityManager;
12
use WMDE\Fundraising\AddressChangeContext\AddressChangeContextFactory;
13
14
class TestAddressChangeContextFactory {
15
16
	private Configuration $doctrineConfig;
17
	private AddressChangeContextFactory $factory;
18
	private Connection $connection;
19
	private ?EntityManager $entityManager;
20
21
	public function __construct( array $config, Configuration $doctrineConfig ) {
22
		$this->doctrineConfig = $doctrineConfig;
23
24
		$this->connection = DriverManager::getConnection( $config['db'] );
25
		$this->factory = new AddressChangeContextFactory();
26
		$this->entityManager = null;
27
	}
28
29
	public function getEntityManager(): EntityManager {
30
		if ( $this->entityManager === null ) {
31
			AnnotationRegistry::registerLoader( 'class_exists' );
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...istry::registerLoader() has been deprecated: This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

31
			/** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerLoader( 'class_exists' );

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
32
33
			$this->doctrineConfig->setMetadataDriverImpl( $this->factory->newMappingDriver() );
34
35
			$this->entityManager = EntityManager::create(
36
				$this->connection,
37
				$this->doctrineConfig
38
			);
39
		}
40
41
		return $this->entityManager;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->entityManager could return the type null which is incompatible with the type-hinted return Doctrine\ORM\EntityManager. Consider adding an additional type-check to rule them out.
Loading history...
42
	}
43
}