Completed
Push — sf_cache ( 8c890f...ff1daa )
by André
14:18
created

AbstractBaseHandlerTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains Test class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Cache\Tests;
10
11
use eZ\Publish\Core\Persistence\Cache\Handler as CacheHandler;
12
use eZ\Publish\Core\Persistence\Cache\SectionHandler as CacheSectionHandler;
13
use eZ\Publish\Core\Persistence\Cache\LocationHandler as CacheLocationHandler;
14
use eZ\Publish\Core\Persistence\Cache\ContentHandler as CacheContentHandler;
15
use eZ\Publish\Core\Persistence\Cache\ContentLanguageHandler as CacheContentLanguageHandler;
16
use eZ\Publish\Core\Persistence\Cache\ContentTypeHandler as CacheContentTypeHandler;
17
use eZ\Publish\Core\Persistence\Cache\UserHandler as CacheUserHandler;
18
use eZ\Publish\Core\Persistence\Cache\TransactionHandler as CacheTransactionHandler;
19
use eZ\Publish\Core\Persistence\Cache\TrashHandler as CacheTrashHandler;
20
use eZ\Publish\Core\Persistence\Cache\UrlAliasHandler as CacheUrlAliasHandler;
21
use eZ\Publish\Core\Persistence\Cache\ObjectStateHandler as CacheObjectStateHandler;
22
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
23
use Symfony\Component\Cache\CacheItem;
24
use PHPUnit_Framework_TestCase;
25
26
/**
27
 * Abstract test case for spi cache impl.
28
 */
29
abstract class AbstractBaseHandlerTest extends PHPUnit_Framework_TestCase
30
{
31
    /**
32
     * @var \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface|\PHPUnit_Framework_MockObject_MockObject
33
     */
34
    protected $cacheMock;
35
36
    /**
37
     * @var \eZ\Publish\SPI\Persistence\Handler|\PHPUnit_Framework_MockObject_MockObject
38
     */
39
    protected $persistenceHandlerMock;
40
41
    /**
42
     * @var \eZ\Publish\Core\Persistence\Cache\Handler
43
     */
44
    protected $persistenceCacheHandler;
45
46
    /**
47
     * @var \eZ\Publish\Core\Persistence\Cache\PersistenceLogger|\PHPUnit_Framework_MockObject_MockObject
48
     */
49
    protected $loggerMock;
50
51
    /**
52
     * @var \Closure
53
     */
54
    protected $cacheItemsClosure;
55
56
    /**
57
     * Setup the HandlerTest.
58
     */
59
    final protected function setUp()
60
    {
61
        parent::setUp();
62
63
        $this->persistenceHandlerMock = $this->getMock('eZ\Publish\SPI\Persistence\Handler');
64
        $this->cacheMock = $this->getMock(TagAwareAdapterInterface::class);
65
        $this->loggerMock = $this->getMock('eZ\\Publish\\Core\\Persistence\\Cache\\PersistenceLogger');
66
67
        $this->persistenceCacheHandler = new CacheHandler(
68
            $this->persistenceHandlerMock,
69
            new CacheSectionHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
70
            new CacheLocationHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
71
            new CacheContentHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
72
            new CacheContentLanguageHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
73
            new CacheContentTypeHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
74
            new CacheUserHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
75
            new CacheTransactionHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
76
            new CacheTrashHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
77
            new CacheUrlAliasHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
78
            new CacheObjectStateHandler($this->cacheMock, $this->persistenceHandlerMock, $this->loggerMock),
79
            $this->loggerMock,
80
            $this->cacheMock
81
        );
82
83
        $this->cacheItemsClosure = \Closure::bind(
84
            function ($key, $value, $isHit, $defaultLifetime = 0) {
85
                $item = new CacheItem();
86
                $item->key = $key;
0 ignored issues
show
Bug introduced by
The property key cannot be accessed from this context as it is declared protected in class Symfony\Component\Cache\CacheItem.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
87
                $item->value = $value;
0 ignored issues
show
Bug introduced by
The property value cannot be accessed from this context as it is declared protected in class Symfony\Component\Cache\CacheItem.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
88
                $item->isHit = $isHit;
0 ignored issues
show
Bug introduced by
The property isHit cannot be accessed from this context as it is declared protected in class Symfony\Component\Cache\CacheItem.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
89
                $item->defaultLifetime = $defaultLifetime;
0 ignored issues
show
Bug introduced by
The property defaultLifetime cannot be accessed from this context as it is declared protected in class Symfony\Component\Cache\CacheItem.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
90
91
                return $item;
92
            },
93
            null,
94
            CacheItem::class
95
        );
96
    }
97
98
    /**
99
     * Tear down test (properties).
100
     */
101
    final protected function tearDown()
102
    {
103
        unset($this->cacheMock);
104
        unset($this->persistenceHandlerMock);
105
        unset($this->persistenceCacheHandler);
106
        unset($this->loggerMock);
107
        unset($this->cacheItemsClosure);
108
        parent::tearDown();
109
    }
110
111
    /**
112
     * @param $key
113
     * @param null $value If null the cache item will be assumed to be a cache miss here.
114
     * @param int $defaultLifetime
115
     *
116
     * @return CacheItem
117
     */
118
    final protected function getCacheItem($key, $value = null, $defaultLifetime = 0)
119
    {
120
        $cacheItemsClosure = $this->cacheItemsClosure;
121
        return $cacheItemsClosure($key, $value, !!$value, $defaultLifetime);
122
    }
123
}
124