testFactoryProcessesWithoutErrors()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 44
rs 8.8571
cc 1
eloc 31
nc 1
nop 0
1
<?php
2
3
namespace JhFlexiTimeTest\Controller\Factory;
4
5
use JhFlexiTime\Controller\Factory\BookingControllerFactory;
6
use Zend\Mvc\Controller\PluginManager;
7
use Zend\ServiceManager\ServiceManager;
8
use Zend\View\HelperPluginManager;
9
10
/**
11
 * Class BookingControllerFactoryTest
12
 * @package JhFlexiTimeTest\Controller\Factory
13
 * @author Aydin Hassan <[email protected]>
14
 */
15
class BookingControllerFactoryTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testFactoryProcessesWithoutErrors()
18
    {
19
20
        $bookingService = $this
21
            ->getMockBuilder('JhFlexiTime\Service\BookingService')
22
            ->disableOriginalConstructor()
23
            ->getMock();
24
25
        $timeCalculatorService = $this
26
            ->getMockBuilder('JhFlexiTime\Service\TimeCalculatorService')
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
30
        $formElementManager = new ServiceManager();
31
        $formElementManager->setService('JhFlexiTime\Form\BookingForm', $this->getMock('Zend\Form\FormInterface'));
32
        $userSettingsRepository = $this->getMock('JhFlexiTime\Repository\UserSettingsRepositoryInterface');
33
        $services = [
34
            'JhFlexiTime\Service\BookingService'        => $bookingService,
35
            'JhFlexiTime\Service\TimeCalculatorService' => $timeCalculatorService,
36
            'FormElementManager'                        => $formElementManager,
37
            'JhFlexiTime\Repository\UserSettingsRepository' => $userSettingsRepository,
38
        ];
39
40
        $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface');
41
        $serviceLocator
42
            ->expects($this->any())
43
            ->method('get')
44
            ->will(
45
                $this->returnCallback(
46
                    function ($serviceName) use ($services) {
47
                        return $services[$serviceName];
48
                    }
49
                )
50
            );
51
52
        $controllerPluginManager = new PluginManager();
53
        $controllerPluginManager->setServiceLocator($serviceLocator);
54
55
        $factory = new BookingControllerFactory();
56
        $this->assertInstanceOf(
57
            'JhFlexiTime\Controller\BookingController',
58
            $factory->createService($controllerPluginManager)
59
        );
60
    }
61
}
62