Completed
Pull Request — master (#494)
by Thomas Mauro
38:48 queued 26:02
created

testCreateServiceWithNotEnabledToolbar()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 15
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 DoctrineORMModuleTest\Yuml;
21
22
use PHPUnit_Framework_TestCase;
23
use DoctrineORMModule\Yuml\YumlController;
24
use DoctrineORMModule\Yuml\YumlControllerFactory;
25
use Zend\ServiceManager\AbstractPluginManager;
26
use Zend\ServiceManager\ServiceLocatorInterface;
27
28
class YumlControllerFactoryTest extends PHPUnit_Framework_TestCase
29
{
30
    public function testCreateService()
31
    {
32
        $config = [
33
            'zenddevelopertools' => [
34
                'toolbar' => [
35
                    'enabled' => true
36
                ]
37
            ]
38
        ];
39
40
        $serviceLocator = $this->getMock(ServiceLocatorInterface::class);
41
        $pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
42
            ->disableOriginalConstructor()
43
            ->getMock();
44
45
        $serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
46
        $pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
47
48
        $factory = new YumlControllerFactory();
49
        $controller = $factory->createService($pluginManager);
50
51
        $this->assertInstanceOf(YumlController::class, $controller);
52
    }
53
54
    public function testCreateServiceWithNotEnabledToolbar()
55
    {
56
        $config = [
57
            'zenddevelopertools' => [
58
                'toolbar' => [
59
                    'enabled' => false
60
                ]
61
            ]
62
        ];
63
64
        $serviceLocator = $this->getMock(ServiceLocatorInterface::class);
65
        $pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
69
        $serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
70
        $pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
71
72
        $factory = new YumlControllerFactory();
73
74
        $this->setExpectedException(\Zend\ServiceManager\Exception\ServiceNotFoundException::class);
75
        $controller = $factory->createService($pluginManager);
76
77
        $this->assertInstanceOf(YumlController::class, $controller);
78
    }
79
80
    public function testCreateServiceWithNoConfigKey()
81
    {
82
        $config = [
83
            'zenddevelopertools' => []
84
        ];
85
86
        $serviceLocator = $this->getMock(ServiceLocatorInterface::class);
87
        $pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
88
            ->disableOriginalConstructor()
89
            ->getMock();
90
91
        $serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
92
        $pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
93
94
        $factory = new YumlControllerFactory();
95
96
        $this->setExpectedException(\Zend\ServiceManager\Exception\ServiceNotFoundException::class);
97
        $controller = $factory->createService($pluginManager);
98
99
        $this->assertInstanceOf(YumlController::class, $controller);
100
    }
101
}
102