ProxyFactoryTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 8 3
A testReferenceProxyDelegatesLoadingToThePersister() 0 23 1
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']);
0 ignored issues
show
Unused Code introduced by
The call to ProxyFactory::getProxy() has too many arguments starting with $query['documentName'].

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.

Loading history...
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