Completed
Pull Request — master (#131)
by Mike
04:10
created

testReferenceProxyDelegatesLoadingToThePersister()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
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;
0 ignored issues
show
Unused Code introduced by
The property $uowMock is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
25
    private $dmMock;
0 ignored issues
show
Unused Code introduced by
The property $dmMock is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
    private $persisterMock;
0 ignored issues
show
Unused Code introduced by
The property $persisterMock is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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->getMockBuilder('Doctrine\ODM\CouchDB\UnitOfWork', array('refresh'), array(), '', false)
0 ignored issues
show
Unused Code introduced by
The call to ProxyFactoryTest::getMockBuilder() has too many arguments starting with array('refresh').

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...
55
            ->disableOriginalConstructor()
56
            ->getMock();
57
        $uowMock->expects($this->atLeastOnce())
58
                      ->method('refresh')
59
                      ->with($this->isInstanceOf($proxyClass));
60
61
        $dmMock = new DocumentManagerMock();
62
        $dmMock->setUnitOfWorkMock($uowMock);
63
64
        $this->proxyFactory = new ProxyFactory($dmMock, __DIR__ . '/generated', 'Proxies', true);
65
66
        $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...
67
68
        $this->assertInstanceOf('Doctrine\ODM\CouchDB\Proxy\Proxy', $proxy);
69
70
        $proxy->getDescription();
71
    }
72
}
73
74
class DocumentManagerMock extends \Doctrine\ODM\CouchDB\DocumentManager
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
75
{
76
    private $uowMock;
77
78
    public function __construct()
79
    {
80
        
81
    }
82
83
    public function getClassMetadata($class)
84
    {
85
        $metadata = new \Doctrine\ODM\CouchDB\Mapping\ClassMetadata($class);
86
        $metadata->initializeReflection(new RuntimeReflectionService());
87
        $metadata->wakeupReflection(new RuntimeReflectionService());
88
89
        return $metadata;
90
    }
91
92
    public function getMetadataFactory()
93
    {
94
        $dm = \Doctrine\ODM\CouchDB\DocumentManager::create(array('dbname' => 'test'));
95
        return new \Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory($dm);
96
    }
97
98
    public function setUnitOfWorkMock($mock)
99
    {
100
        $this->uowMock = $mock;
101
    }
102
103
    public function getUnitOfWork()
104
    {
105
        return $this->uowMock;
106
    }
107
108
}
109