Completed
Pull Request — master (#494)
by Thomas Mauro
27:08 queued 16:39
created

YumlControllerFactoryTest::testCreateService()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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