public function testcreateAdmin() { $data = array('email' => '*****@*****.**', 'admin_group_id' => '1', 'name' => 'testJohn', 'status' => 'active', 'password' => '1345'); $newId = 1; $adminModel = new \Model_Admin(); $adminModel->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($adminModel)); $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue($newId)); $logMock = $this->getMockBuilder('\\Box_Log')->getMock(); $systemService = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock(); $systemService->expects($this->atLeastOnce())->method('getParamValue'); $emailServiceMock = $this->getMockBuilder('\\Box\\Mod\\Email\\Service')->getMock(); $emailServiceMock->expects($this->atLeastOnce())->method('sendMail'); $urlMock = $this->getMockBuilder('\\Box_Url')->getMock(); $urlMock->expects($this->atLeastOnce())->method('link')->willReturn(''); $urlMock->expects($this->atLeastOnce())->method('adminLink')->willReturn(''); $passwordMock = $this->getMockBuilder('\\Box_Password')->getMock(); $passwordMock->expects($this->atLeastOnce())->method('hashIt')->with($data['password']); $di = new \Box_Di(); $di['logger'] = $logMock; $di['db'] = $dbMock; $di['mod_service'] = $di->protect(function ($serviceName) use($systemService, $emailServiceMock) { if ('system' == $serviceName) { return $systemService; } if ('Email' == $serviceName) { return $emailServiceMock; } }); $di['url'] = $urlMock; $di['password'] = $passwordMock; $service = new \Box\Mod\Staff\Service(); $service->setDi($di); $result = $service->createAdmin($data); $this->assertInternalType('int', $result); $this->assertEquals($newId, $result); }