GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a42b47...a111ac )
by Florian
03:12
created

getMetadataDriverImplementation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Stinger Enity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\EntitySearchBundle\Tests;
13
14
use Doctrine\Common\EventManager;
15
use Doctrine\ORM\Configuration;
16
use Doctrine\ORM\EntityManager;
17
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
18
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
19
use Doctrine\ORM\Repository\DefaultRepositoryFactory;
20
use Doctrine\ORM\Tools\SchemaTool;
21
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
22
23
abstract class AbstractORMTestCase extends AbstractTestCase {
24
25
	/**
26
	 *
27
	 * @var EntityManager
28
	 */
29
	protected $em;
30
31
	/**
32
	 * EntityManager mock object together with
33
	 * annotation mapping driver and pdo_sqlite
34
	 * database in memory
35
	 *
36
	 * @param EventManager $evm        	
37
	 *
38
	 * @return EntityManager
39
	 */
40
	protected function getMockSqliteEntityManager(EventManager $evm = null, Configuration $config = null) {
41
		$conn = array(
42
			'driver' => 'pdo_sqlite',
43
			'memory' => true 
44
		);
45
		$config = null === $config ? $this->getMockAnnotatedConfig() : $config;
46
		$em = EntityManager::create($conn, $config, $evm ?: $this->getEventManager());
47
		$schema = array_map(function ($class) use ($em) {
48
			return $em->getClassMetadata($class);
49
		}, (array)$this->getUsedEntityFixtures());
50
		$schemaTool = new SchemaTool($em);
51
		$schemaTool->dropSchema(array());
52
		$schemaTool->createSchema($schema);
53
		return $this->em = $em;
54
	}
55
56
	protected function getEventManager() {
57
		return new EventManager();
58
	}
59
60
	/**
61
	 * Get annotation mapping configuration
62
	 *
63
	 * @return \Doctrine\ORM\Configuration
64
	 */
65
	protected function getMockAnnotatedConfig() {
66
		// We need to mock every method except the ones which
67
		// handle the filters
68
		$configurationClass = 'Doctrine\ORM\Configuration';
69
		$refl = new \ReflectionClass($configurationClass);
70
		$methods = $refl->getMethods();
71
		$mockMethods = array();
72
		foreach($methods as $method) {
73
			if($method->name !== 'addFilter' && $method->name !== 'getFilterClassName') {
74
				$mockMethods[] = $method->name;
75
			}
76
		}
77
		$config = $this->getMock($configurationClass, $mockMethods);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
78
		$config->expects($this->once())->method('getProxyDir')->will($this->returnValue(__DIR__ . '/../../temp'));
79
		$config->expects($this->once())->method('getProxyNamespace')->will($this->returnValue('Proxy'));
80
		$config->expects($this->any())->method('getDefaultQueryHints')->will($this->returnValue(array()));
81
		$config->expects($this->once())->method('getAutoGenerateProxyClasses')->will($this->returnValue(true));
82
		$config->expects($this->once())->method('getClassMetadataFactoryName')->will($this->returnValue('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'));
83
		$mappingDriver = $this->getMetadataDriverImplementation();
84
		$config->expects($this->any())->method('getMetadataDriverImpl')->will($this->returnValue($mappingDriver));
85
		$config->expects($this->any())->method('getDefaultRepositoryClassName')->will($this->returnValue('Doctrine\\ORM\\EntityRepository'));
86
		$config->expects($this->any())->method('getQuoteStrategy')->will($this->returnValue(new DefaultQuoteStrategy()));
87
		$config->expects($this->any())->method('getNamingStrategy')->will($this->returnValue(new DefaultNamingStrategy()));
88
		$config->expects($this->once())->method('getRepositoryFactory')->will($this->returnValue(new DefaultRepositoryFactory()));
89
		return $config;
90
	}
91
92
	/**
93
	 * Creates default mapping driver
94
	 *
95
	 * @return \Doctrine\ORM\Mapping\Driver\Driver
96
	 */
97
	protected function getMetadataDriverImplementation() {
0 ignored issues
show
Coding Style introduced by
getMetadataDriverImplementation uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
98
		return new AnnotationDriver($_ENV['annotation_reader']);
99
	}
100
}