public function setUp() { $this->userService = $this->getMock('ZfcUser\\Service\\User'); $this->options = $this->getMock('ZfcUser\\Options\\ModuleOptions'); $this->registerForm = $this->getMockBuilder('ZfcUser\\Form\\Register')->disableOriginalConstructor()->getMock(); $this->loginForm = $this->getMockBuilder('ZfcUser\\Form\\Login')->disableOriginalConstructor()->getMock(); $controller = new Controller($this->userService, $this->options, $this->registerForm, $this->loginForm); $this->controller = $controller; $this->zfcUserAuthenticationPlugin = $this->getMock('ZfcUser\\Controller\\Plugin\\ZfcUserAuthentication'); $pluginManager = $this->getMock('Zend\\Mvc\\Controller\\PluginManager', array('get')); $pluginManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'helperMockCallbackPluginManagerGet'))); $this->pluginManager = $pluginManager; $controller->setPluginManager($pluginManager); }
/** * @dataProvider providerTestSetterGetterServices * @depend testActionControllHasIdentity */ public function testSetterGetterServices($methode, $useServiceLocator, $servicePrototype, $serviceName, $callback = null) { $controller = new Controller(); $controller->setPluginManager($this->pluginManager); // $controller = $this->controller; if (is_callable($callback)) { call_user_func($callback, $this, $controller); } if ($useServiceLocator) { $serviceLocator = $this->getMock('\\Zend\\ServiceManager\\ServiceLocatorInterface'); $serviceLocator->expects($this->once())->method('get')->with($serviceName)->will($this->returnValue($servicePrototype)); $controller->setServiceLocator($serviceLocator); } else { call_user_func(array($controller, 'set' . $methode), $servicePrototype); } $result = call_user_func(array($controller, 'get' . $methode)); $this->assertInstanceOf(get_class($servicePrototype), $result); $this->assertSame($servicePrototype, $result); // we need two check for every case $result = call_user_func(array($controller, 'get' . $methode)); $this->assertInstanceOf(get_class($servicePrototype), $result); $this->assertSame($servicePrototype, $result); }