1 | <?php |
||
12 | class BaseTestCaseOrm extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | protected $doctrine; |
||
15 | |||
16 | private function getMockAnnotatedConfig() |
||
17 | { |
||
18 | $config = $this->createMock('Doctrine\ORM\Configuration'); |
||
19 | $config |
||
20 | ->expects($this->once()) |
||
21 | ->method('getProxyDir') |
||
22 | ->will($this->returnValue(__DIR__ . '/temp')) |
||
23 | ; |
||
24 | |||
25 | $config |
||
26 | ->expects($this->once()) |
||
27 | ->method('getProxyNamespace') |
||
28 | ->will($this->returnValue('Proxy')) |
||
29 | ; |
||
30 | |||
31 | $config |
||
32 | ->expects($this->once()) |
||
33 | ->method('getAutoGenerateProxyClasses') |
||
34 | ->will($this->returnValue(true)) |
||
35 | ; |
||
36 | |||
37 | $config |
||
38 | ->expects($this->once()) |
||
39 | ->method('getClassMetadataFactoryName') |
||
40 | ->will($this->returnValue('Doctrine\\ORM\\Mapping\\ClassMetadataFactory')) |
||
41 | ; |
||
42 | |||
43 | $mappingDriver = $this->getMetadataDriverImplementation(); |
||
44 | |||
45 | $config |
||
46 | ->expects($this->any()) |
||
47 | ->method('getMetadataDriverImpl') |
||
48 | ->will($this->returnValue($mappingDriver)) |
||
49 | ; |
||
50 | |||
51 | $config |
||
52 | ->expects($this->any()) |
||
53 | ->method('getDefaultRepositoryClassName') |
||
54 | ->will($this->returnValue('Doctrine\\ORM\\EntityRepository')) |
||
55 | ; |
||
56 | |||
57 | $quoteStrategy = new DefaultQuoteStrategy(); |
||
58 | |||
59 | $config |
||
60 | ->expects($this->any()) |
||
61 | ->method('getQuoteStrategy') |
||
62 | ->will($this->returnValue($quoteStrategy)) |
||
63 | ; |
||
64 | |||
65 | $repositoryFactory = new DefaultRepositoryFactory(); |
||
66 | |||
67 | $config |
||
68 | ->expects($this->any()) |
||
69 | ->method('getRepositoryFactory') |
||
70 | ->will($this->returnValue($repositoryFactory)) |
||
71 | ; |
||
72 | |||
73 | return $config; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Creates default mapping driver |
||
78 | * |
||
79 | * @return \Doctrine\ORM\Mapping\Driver\Driver |
||
80 | */ |
||
81 | protected function getMetadataDriverImplementation() |
||
88 | |||
89 | /** |
||
90 | * EntityManager mock object together with |
||
91 | * annotation mapping driver and pdo_sqlite |
||
92 | * database in memory |
||
93 | * |
||
94 | * @param EventManager $evm |
||
95 | * @return EntityManager |
||
96 | */ |
||
97 | protected function getDoctrine() |
||
131 | } |
||
132 |
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: