Пример #1
0
 public function testcreate_Exception()
 {
     $data = array('email' => '*****@*****.**', 'admin_group_id' => '1', 'name' => 'testJohn', 'status' => 'active', 'password' => '1345');
     $newId = 1;
     $adminModel = new \Model_Admin();
     $adminModel->loadBean(new \RedBeanPHP\OODBBean());
     $systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock();
     $systemServiceMock->expects($this->atLeastOnce())->method('checkLimits');
     $eventsMock = $this->getMockBuilder('\\Box_EventManager')->getMock();
     $eventsMock->expects($this->atLeastOnce())->method('fire');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($adminModel));
     $dbMock->expects($this->atLeastOnce())->method('store')->willThrowException(new \RedBeanPHP\RedException());
     $logMock = $this->getMockBuilder('\\Box_Log')->getMock();
     $passwordMock = $this->getMockBuilder('\\Box_Password')->getMock();
     $passwordMock->expects($this->atLeastOnce())->method('hashIt')->with($data['password']);
     $di = new \Box_Di();
     $di['events_manager'] = $eventsMock;
     $di['logger'] = $logMock;
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function () use($systemServiceMock) {
         return $systemServiceMock;
     });
     $di['password'] = $passwordMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $service = new \Box\Mod\Staff\Service();
     $service->setDi($di);
     $this->setExpectedException('\\Box_Exception', sprintf('Staff member with email %s is already registered', $data['email']), 788954);
     $service->create($data);
 }