Completed
Push — master ( a8b991...dda2b8 )
by Marco
06:05 queued 02:56
created

CacheProviderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 99
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testFetchMultiWillFilterNonRequestedKeys() 0 27 1
B testFailedDeleteAllDoesNotChangeNamespaceVersion() 0 37 1
B testSaveMultipleNoFail() 0 30 1
1
<?php
2
3
namespace Doctrine\Tests\Common\Cache;
4
5
class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase
6
{
7
    public function testFetchMultiWillFilterNonRequestedKeys()
8
    {
9
        /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
10
        $cache = $this->getMockForAbstractClass(
11
            'Doctrine\Common\Cache\CacheProvider',
12
            array(),
13
            '',
14
            true,
15
            true,
16
            true,
17
            array('doFetchMultiple')
18
        );
19
20
        $cache
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\CacheProvider.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
21
            ->expects($this->once())
22
            ->method('doFetchMultiple')
23
            ->will($this->returnValue(array(
24
                '[foo][1]' => 'bar',
25
                '[bar][1]' => 'baz',
26
                '[baz][1]' => 'tab',
27
            )));
28
29
        $this->assertEquals(
30
            array('foo' => 'bar', 'bar' => 'baz'),
31
            $cache->fetchMultiple(array('foo', 'bar'))
0 ignored issues
show
Bug introduced by
The method fetchMultiple does only exist in Doctrine\Common\Cache\CacheProvider, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
32
        );
33
    }
34
35
    public function testFailedDeleteAllDoesNotChangeNamespaceVersion()
36
    {
37
        /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
38
        $cache = $this->getMockForAbstractClass(
39
            'Doctrine\Common\Cache\CacheProvider',
40
            array(),
41
            '',
42
            true,
43
            true,
44
            true,
45
            array('doFetch', 'doSave', 'doContains')
46
        );
47
48
        $cache
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\CacheProvider.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
49
            ->expects($this->once())
50
            ->method('doFetch')
51
            ->with('DoctrineNamespaceCacheKey[]')
52
            ->will($this->returnValue(false));
53
54
        // doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion()
55
        $cache
56
            ->expects($this->once())
57
            ->method('doSave')
58
            ->with('DoctrineNamespaceCacheKey[]')
59
            ->will($this->returnValue(false));
60
61
        // After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards
62
        // would be lost outside the current instance.
63
        $cache
64
            ->expects($this->once())
65
            ->method('doContains')
66
            ->with('[key][1]')
67
            ->will($this->returnValue(true));
68
69
        $this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails');
0 ignored issues
show
Bug introduced by
The method deleteAll does only exist in Doctrine\Common\Cache\CacheProvider, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
70
        $cache->contains('key');
0 ignored issues
show
Bug introduced by
The method contains does only exist in Doctrine\Common\Cache\CacheProvider, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
71
    }
72
73
    public function testSaveMultipleNoFail()
74
    {
75
        /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
76
        $cache = $this->getMockForAbstractClass(
77
            'Doctrine\Common\Cache\CacheProvider',
78
            array(),
79
            '',
80
            true,
81
            true,
82
            true,
83
            array('doSave')
84
        );
85
86
        $cache
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\Common\Cache\CacheProvider.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87
            ->expects($this->at(1))
88
            ->method('doSave')
89
            ->with('[kerr][1]', 'verr', 0)
90
            ->will($this->returnValue(false));
91
92
        $cache
93
            ->expects($this->at(2))
94
            ->method('doSave')
95
            ->with('[kok][1]', 'vok', 0)
96
            ->will($this->returnValue(true));
97
98
        $cache->saveMultiple(array(
0 ignored issues
show
Bug introduced by
The method saveMultiple does only exist in Doctrine\Common\Cache\CacheProvider, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
99
            'kerr'  => 'verr',
100
            'kok'   => 'vok',
101
        ));
102
    }
103
}
104