public function testExecuteSelect()
 {
     $config = new Configurator(['dsn' => 'mysql:host=localhost;dbname=php_praticas_modernas', 'user' => 'root', 'pass' => '123', 'config' => []]);
     $conn = new Connection($config);
     $conn->conn();
     $select = new Mysql\Select();
     $execute = new Execute($conn);
     $execute->sql($select);
     $data = $execute->findAll();
     $esperado = [['id' => 1, 'name' => 'Erik', 'email' => '*****@*****.**']];
     $this->assertEquals($esperado, $data);
 }
Beispiel #2
0
 public function testShouldRestartApacheServer()
 {
     $temporaryDir = 'app/tmp';
     $configRepository = $this->getMockBuilder('Marvin\\Config\\Repository')->setMethods(['get'])->getMock();
     $configRepository->expects($this->once())->method('get')->with($this->equalTo('app.temporary-dir'))->will($this->returnValue($temporaryDir));
     $vhManager = $this->getMockBuilder('Marvin\\Contracts\\HostManager')->setMethods([])->getMock();
     $vhManager->expects($this->once())->method('get')->with($this->equalTo('file-name'))->will($this->returnValue('marvin.dev.conf'));
     $execute = new Execute($configRepository);
     $execute->setHostManager($vhManager);
     $this->assertRegExp('/Restart Success/', $execute->restart());
     $this->assertRegExp('/sudo service apache2 reload/', $execute->restart());
 }
Beispiel #3
0
 public static function startNewSession($username, $password, $gcm_id)
 {
     $success = true;
     //test if the username and password are correct
     if (user::isLogin($username, $password)) {
         //retrieve user info
         $user_info = user::getUserByUsername($username);
         $e = user::setGCM($user_info['id'], $gcm_id);
         $success = $success && $e;
         //check if user has existing session:
         if (session::does_user_have_session($user_info['id'])) {
             //remove the session
             $session_info = session::get_last_session_for_user_id($user_info['id']);
             session::delete_session_by_id($session_info['id']);
         }
         //generate a unique hash
         $newHash = md5(random::generateString(10));
         while (!session::is_unique_hash($newHash)) {
             $newHash = md5(random::generateString(10));
         }
         //create a session
         $res = session::add_new_session($user_info['id'], $newHash, "0");
         $success = $success && $res;
         if (!$success) {
             Execute::$lastErrorMessage = "failed to add new changes to database";
             Report::error(__METHOD__ . "," . __LINE__, "failed to new cahnges to database");
         }
         return $success;
     } else {
         Execute::$lastErrorMessage = "trying to login with an incorrect username or password";
         Report::warning(__METHOD__ . "," . __LINE__, "trying to login with an incorrect username or password");
         return false;
         //trying to log in with an incorrect username or password
     }
 }
Beispiel #4
0
 public function startNewGame()
 {
     if (XmlRequestValidator::isValidStartPendingGameRequest($this->requestData)) {
         $session = $this->requestData->body->session;
         $size = $this->requestData->body->size;
         if (safe_input::is_valid_session_hash($session) && safe_input::is_number($size) && $size > 1) {
             //chkec if the session hash exists
             $session_info = session::get_session_by_hash($session);
             if ($session_info != null) {
                 $res = Execute::newPendingGame($session, $size);
                 if ($res) {
                     $this->response = XmlBuilder::startNewPendingGameSuccessfullResponse("plain", $session);
                 } else {
                     //faild to add new game
                     Report::error(__METHOD__ . "," . __LINE__, "failed to add new pending game");
                     $this->response = XmlBuilder::failed_response("plain", 5, 0, "failed to add new pending game, try again");
                 }
             } else {
                 //the given hash doesn't exist in the database
                 Report::warning(__METHOD__ . "," . __LINE__, "start new pending game request contains a session hash that does not exist in the database: hash=" . $session);
                 $this->response = XmlBuilder::failed_response("plain", 5, 1, "expired session");
             }
         } else {
             //invalid data passed
             Report::error(__METHOD__ . "," . __LINE__, "start new pending game request contains an incorrectly formatted session hash or game size, size:" . $size);
             $this->response = XmlBuilder::failed_response("plain", 5, 0, "invalid session or gcm id");
         }
     } else {
         //xml request was not formatted correctly
         Report::error(__METHOD__ . "," . __LINE__, "invalid new pending game request!");
         $this->invalidRequest();
     }
 }