Beispiel #1
0
 public function testguestCreateClient()
 {
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $clientModel->id = 1;
     $data = array('password' => uniqid(), 'email' => '*****@*****.**', 'first_name' => 'test');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($clientModel));
     $dbMock->expects($this->atLeastOnce())->method('store');
     $eventManagerMock = $this->getMockBuilder('\\Box_EventManager')->getMock();
     $eventManagerMock->expects($this->exactly(2))->method('fire');
     $requestMock = $this->getMockBuilder('\\Box_Request')->getMock();
     $ip = '10.10.10.2';
     $requestMock->expects($this->atLeastOnce())->method('getClientAddress')->will($this->returnValue($ip));
     $passwordMock = $this->getMockBuilder('\\Box_Password')->getMock();
     $passwordMock->expects($this->atLeastOnce())->method('hashIt')->with($data['password']);
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['events_manager'] = $eventManagerMock;
     $di['logger'] = new \Box_Log();
     $di['request'] = $requestMock;
     $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\Client\Service();
     $service->setDi($di);
     $result = $service->guestCreateClient($data);
     $this->assertInstanceOf('\\Model_Client', $result);
     $this->assertNotEquals($data['password'], $result->pass, 'Password is not hashed');
     $this->assertEquals($ip, $result->ip, 'IP address is not saved while creating client');
 }