Completed
Pull Request — master (#508)
by Oliver
03:04
created

YumlControllerFactoryTest::testCreateService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 14
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->createMock(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->createMock(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->expectException(\Zend\ServiceManager\Exception\ServiceNotFoundException::class);
75
        $factory->createService($pluginManager);
76
    }
77
78
    public function testCreateServiceWithNoConfigKey()
79
    {
80
        $config = [
81
            'zenddevelopertools' => [],
82
        ];
83
84
        $serviceLocator = $this->createMock(ServiceLocatorInterface::class);
85
        $pluginManager = $this->getMockBuilder(AbstractPluginManager::class)
86
            ->disableOriginalConstructor()
87
            ->getMock();
88
89
        $serviceLocator->expects($this->once())->method('get')->with('config')->willReturn($config);
90
        $pluginManager->expects($this->once())->method('getServiceLocator')->willReturn($serviceLocator);
91
92
        $factory = new YumlControllerFactory();
93
94
        $this->expectException(\Zend\ServiceManager\Exception\ServiceNotFoundException::class);
95
        $factory->createService($pluginManager);
96
    }
97
}
98