Completed
Push — master ( 2673b4...0c8159 )
by Gianluca
29:49 queued 25:20
created

CacheFactoryTest::testCreateZendCache()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 32
rs 8.8571
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineModuleTest\Service;
21
22
use DoctrineModule\Service\CacheFactory;
23
use PHPUnit_Framework_TestCase as BaseTestCase;
24
use Zend\ServiceManager\ServiceManager;
25
26
/**
27
 * Test for {@see \DoctrineModule\Service\CacheFactory}
28
 *
29
 * @author Marco Pivetta <[email protected]>
30
 */
31
class CacheFactoryTest extends BaseTestCase
32
{
33
    /**
34
     * @covers \DoctrineModule\Service\CacheFactory::createService
35
     */
36
    public function testWillSetNamespace()
37
    {
38
        $factory        = new CacheFactory('foo');
39
        $serviceManager = new ServiceManager();
40
        $serviceManager->setService(
41
            'Configuration',
42
            array(
43
                 'doctrine' => array(
44
                     'cache' => array(
45
                         'foo' => array(
46
                             'namespace' => 'bar',
47
                         ),
48
                     ),
49
                 ),
50
            )
51
        );
52
53
        /* @var $service \Doctrine\Common\Cache\ArrayCache */
54
        $service = $factory->createService($serviceManager);
55
56
        $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $service);
57
        $this->assertSame('bar', $service->getNamespace());
58
    }
59
60
    /**
61
     * @covers \DoctrineModule\Service\CacheFactory::createService
62
     * @group 547
63
     */
64
    public function testCreateZendCache()
65
    {
66
        $factory        = new CacheFactory('phpunit');
67
        $serviceManager = new ServiceManager();
68
        $serviceManager->setAlias('Config', 'Configuration');
69
        $serviceManager->setService(
70
            'Configuration',
71
            [
72
                'doctrine' => [
73
                    'cache' => [
74
                        'phpunit' => [
75
                            'class' => 'DoctrineModule\Cache\ZendStorageCache',
76
                            'instance' => 'my-zend-cache',
77
                            'namespace' => 'DoctrineModule',
78
                        ],
79
                    ],
80
                ],
81
                'caches' => [
82
                    'my-zend-cache' => [
83
                        'adapter' => [
84
                            'name' => 'blackhole'
85
                        ]
86
                    ]
87
                ]
88
            ]
89
        );
90
        $serviceManager->addAbstractFactory('Zend\Cache\Service\StorageCacheAbstractServiceFactory');
91
92
        $cache = $factory->createService($serviceManager);
93
94
        $this->assertInstanceOf('DoctrineModule\Cache\ZendStorageCache', $cache);
95
    }
96
97
    public function testCreatePredisCache()
98
    {
99
        $factory        = new CacheFactory('predis');
100
        $serviceManager = new ServiceManager();
101
        $serviceManager->setService(
102
            'Configuration',
103
            [
104
                'doctrine' => [
105
                    'cache' => [
106
                        'predis' => [
107
                            'class' => 'Doctrine\Common\Cache\PredisCache',
108
                            'instance' => 'my_predis_alias',
109
                            'namespace' => 'DoctrineModule',
110
                        ],
111
                    ],
112
                ],
113
            ]
114
        )->setService(
115
            'my_predis_alias',
116
            $this->getMock('Predis\ClientInterface')
117
        );
118
        $cache = $factory->createService($serviceManager);
119
120
        $this->assertInstanceOf('Doctrine\Common\Cache\PredisCache', $cache);
121
    }
122
}
123