1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ODM\CouchDB\Proxy; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; |
6
|
|
|
use Doctrine\ODM\CouchDB\Proxy\ProxyFactory; |
7
|
|
|
use Doctrine\ODM\CouchDB\DocumentManager; |
8
|
|
|
use Doctrine\ODM\CouchDB\UnitOfWork; |
9
|
|
|
use Doctrine\ODM\CouchDB\Mapping\ClassMetadata; |
10
|
|
|
use Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory; |
11
|
|
|
|
12
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceCart; |
13
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer; |
14
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceFeature; |
15
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceProduct; |
16
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceShipping; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Test the proxy factory. |
20
|
|
|
* @author Nils Adermann <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ProxyFactoryTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBTestCase |
23
|
|
|
{ |
24
|
|
|
private $uowMock; |
25
|
|
|
private $dmMock; |
26
|
|
|
private $persisterMock; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \Doctrine\ODM\CouchDB\Proxy\ProxyFactory |
30
|
|
|
*/ |
31
|
|
|
private $proxyFactory; |
32
|
|
|
|
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function tearDown() |
39
|
|
|
{ |
40
|
|
|
foreach (new \DirectoryIterator(__DIR__ . '/generated') as $file) { |
41
|
|
|
if (strstr($file->getFilename(), '.php')) { |
42
|
|
|
unlink($file->getPathname()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testReferenceProxyDelegatesLoadingToThePersister() |
48
|
|
|
{ |
49
|
|
|
$proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature'; |
50
|
|
|
$modelClass = 'Doctrine\Tests\Models\ECommerce\ECommerceFeature'; |
51
|
|
|
|
52
|
|
|
$query = array('documentName' => '\\'.$modelClass, 'id' => 'SomeUUID'); |
53
|
|
|
|
54
|
|
|
$uowMock = $this->getMock('Doctrine\ODM\CouchDB\UnitOfWork', array('refresh'), array(), '', false); |
55
|
|
|
$uowMock->expects($this->atLeastOnce()) |
56
|
|
|
->method('refresh') |
57
|
|
|
->with($this->isInstanceOf($proxyClass)); |
58
|
|
|
|
59
|
|
|
$dmMock = new DocumentManagerMock(); |
60
|
|
|
$dmMock->setUnitOfWorkMock($uowMock); |
61
|
|
|
|
62
|
|
|
$this->proxyFactory = new ProxyFactory($dmMock, __DIR__ . '/generated', 'Proxies', true); |
63
|
|
|
|
64
|
|
|
$proxy = $this->proxyFactory->getProxy($modelClass, $query['id'], $query['documentName']); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->assertInstanceOf('Doctrine\ODM\CouchDB\Proxy\Proxy', $proxy); |
67
|
|
|
|
68
|
|
|
$proxy->getDescription(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
class DocumentManagerMock extends \Doctrine\ODM\CouchDB\DocumentManager |
73
|
|
|
{ |
74
|
|
|
private $uowMock; |
75
|
|
|
|
76
|
|
|
public function __construct() |
77
|
|
|
{ |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getClassMetadata($class) |
82
|
|
|
{ |
83
|
|
|
$metadata = new \Doctrine\ODM\CouchDB\Mapping\ClassMetadata($class); |
84
|
|
|
$metadata->initializeReflection(new RuntimeReflectionService()); |
85
|
|
|
$metadata->wakeupReflection(new RuntimeReflectionService()); |
86
|
|
|
|
87
|
|
|
return $metadata; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getMetadataFactory() |
91
|
|
|
{ |
92
|
|
|
$dm = \Doctrine\ODM\CouchDB\DocumentManager::create(array('dbname' => 'test')); |
93
|
|
|
return new \Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory($dm); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setUnitOfWorkMock($mock) |
97
|
|
|
{ |
98
|
|
|
$this->uowMock = $mock; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getUnitOfWork() |
102
|
|
|
{ |
103
|
|
|
return $this->uowMock; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.