当前位置: 首页>>代码示例>>PHP>>正文


PHP game::getNumberOfGames方法代码示例

本文整理汇总了PHP中game::getNumberOfGames方法的典型用法代码示例。如果您正苦于以下问题:PHP game::getNumberOfGames方法的具体用法?PHP game::getNumberOfGames怎么用?PHP game::getNumberOfGames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在game的用法示例。


在下文中一共展示了game::getNumberOfGames方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test

 public function test()
 {
     $username = "howdy";
     $password = "123456";
     $email = "gg@gmail.com";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "gr@gmmail.com";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $gmae_size = 6;
     $this->assertFalse(game::add_new_game($user1ID, "z", $user1ID, $user2ID), "invalid size went through OK!");
     $this->assertFalse(game::add_new_game("s", $gmae_size, $user1ID, $user2ID), "invalid curent player id went through OK!");
     $this->assertFalse(game::add_new_game($user1ID, $gmae_size, "x", $user2ID), "invalid player 1 id went through OK!");
     $this->assertFalse(game::add_new_game($user1ID, $gmae_size, $user1ID, "d"), "invalid player 2 id went through OK!");
     $this->assertFalse(game::add_new_game(20, $gmae_size, $user1ID, $user2ID), "current turn id was different from p1 and p2 and it when through!");
     $this->assertTrue(game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID), "failed to add a new game");
     $this->assertEquals($gmae_size, game::getGameById(1)['size'], "incorrect game size");
     $this->assertEquals($user1ID, game::getGameById(1)['player1ID'], "incorrect player 1 id ");
     $this->assertEquals($user2ID, game::getGameById(1)['player2ID'], "incorrect player 2 id ");
     $this->assertNull(game::getGameById(1)['winnerID'], "winnder ID should be null");
     $this->assertNull(game::getGameById(1)['lastActivityDate'], "lastActivityDate should be null");
     $this->assertEquals(1, game::getNumberOfGames(), "number of games should be equal to 1");
     game::clear_table();
     $this->assertEquals(0, game::getNumberOfGames(), "number of games should be equal to 0");
     game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID);
     $game_id = game::$last_inserted_id;
     $this->assertTrue(game::setLastActivityDate($game_id), "setLastActivityDate is not working");
     $this->assertEquals(time() / 60 % 60, game::getGameById($game_id)['lastActivityDate'] / 60 % 60);
     game::clear_table();
     //security test: passing a user id that is not a number
     $this->assertEquals(-1, game::getNumberOfGamesForUserId("ff"), "getNumberOfGamesForUserId() should accept only numbers");
     //the user shouldn't have any games
     $this->assertEquals(0, game::getNumberOfGamesForUserId($user2ID), "The player shouldn't have any games [getNumberOfGamesForUserId()]");
     game::add_new_game($user1ID, $gmae_size, $user1ID, $user2ID);
     $game_id1 = game::$last_inserted_id;
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user1ID), "player should have 1 game [getNumberOfGamesForUserId()]");
     $username3 = "bla3";
     $password3 = "pass3";
     $email3 = "bla3@gmmail.com";
     user::create_new_user($username3, $password3, $email3);
     $user3ID = user::getUserByUsername($username3)['id'];
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $this->assertTrue(game::add_new_game($user3ID, $gmae_size, $user3ID, $user1ID), "failed to add a new game");
     $game_id2 = game::$last_inserted_id;
     $this->assertEquals(2, game::getNumberOfGames(), "number of games should be equal to 2");
     $this->assertEquals(2, game::getNumberOfGamesForUserId($user1ID), "player should have two games [getNumberOfGamesForUserId()]");
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user2ID), "player should have one game [getNumberOfGamesForUserId()]");
     $this->assertEquals(1, game::getNumberOfGamesForUserId($user3ID), "player should have one game [getNumberOfGamesForUserId()]");
     $this->assertEquals(2, count(game::getAllGamesForUserId($user1ID)), "two games should be returned [game::getAllGamesForUserId()]");
     $this->assertEquals($user1ID, game::getAllGamesForUserId($user1ID)[0]['player1ID'], "[game::getAllGamesForUserId()]");
     $this->assertEquals($user1ID, game::getAllGamesForUserId($user1ID)[1]['player2ID'], "[game::getAllGamesForUserId()]");
     $this->assertNull(game::getAllGamesForUserId(88), "should return null because player doesn't have games [game::getAllGamesForUserId()]");
     $this->assertNull(game::getOpponentId(1000, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId(1000, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId($game_id1, 1000), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId(1000, $user1ID), "[game::getOpponentId]");
     $this->assertEquals($user2ID, game::getOpponentId($game_id1, $user1ID), "[game::getOpponentId]");
     $this->assertEquals($user1ID, game::getOpponentId($game_id1, $user2ID), "[game::getOpponentId]");
     $this->assertEquals($user1ID, game::getOpponentId($game_id2, $user3ID), "[game::getOpponentId]");
     $this->assertEquals($user3ID, game::getOpponentId($game_id2, $user1ID), "[game::getOpponentId]");
     $this->assertNull(game::getOpponentId($game_id2, $user2ID), "[game::getOpponentId]");
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:67,代码来源:table_gameTest.php

示例2: test

 public function test()
 {
     $username = "howdy";
     $password = "123456";
     $email = "gg@gmail.com";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "gr@gmmail.com";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "eee@gmail.com";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     //GameControl::matchPendingGames() ;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g1_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g2_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g3_id = pending_game::$last_inserted_id;
     $this->assertEquals(0, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(2, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     GameControl::matchPendingGames();
     $this->assertEquals(1, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(1, pending_game::get_count_pending_by_size(3), "[pending_game::mathc()]");
     $this->assertEquals(0, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g4_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g5_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g6_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g7_id = pending_game::$last_inserted_id;
     $this->assertEquals(4, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     GameControl::matchPendingGames();
     $this->assertEquals(0, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertEquals(3, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g8_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g9_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g10_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g11_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 5), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g12_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 5), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g13_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 7), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g14_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 7), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g15_id = pending_game::$last_inserted_id;
     $this->assertEquals(3, game::getNumberOfGames(), "[pending_game::mathc()]");
     GameControl::matchPendingGames();
     $this->assertEquals(7, game::getNumberOfGames(), "[pending_game::mathc()]");
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:65,代码来源:GameControlTest.php

示例3: testNewGameRequest

 public function testNewGameRequest()
 {
     //startNewGame()
     $username = "troy";
     $password = "345667";
     $email = "troy1970@gmail.com";
     $username2 = "sandy";
     $password2 = "booha";
     $email2 = "sandy1111@gmail.com";
     user::create_new_user($username, $password, $email);
     user::create_new_user($username2, $password2, $email2);
     $user_info = user::getUserByUsername($username);
     $user_info2 = user::getUserByUsername($username2);
     $session = md5("dfgfds4543");
     $session2 = md5("rtyertyerty");
     $this->assertTrue(session::add_new_session($user_info['id'], $session, "0"));
     $this->assertTrue(session::add_new_session($user_info2['id'], $session2, "0"));
     $xmlFile = file_get_contents("./files/newPendingGameRequest.xml");
     $p = simplexml_load_string($xmlFile);
     $p->body->session = $session;
     $p->body->size = 6;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->assertEquals("5", $pr->body->id, "[new pending game]");
     $this->assertEquals($session, $pr->body->session, "[new pending game]");
     $games = pending_game::get_all_pending_games_for_user_id($user_info['id']);
     $this->assertEquals(1, count($games), "[new pending game]");
     $this->assertEquals(6, $games[0]['size'], "[new pending game]");
     //send an invalid session hash
     $p->body->session = md5("invalid_session");
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("failed", $pr->body->status, "[new pending game]");
     $this->assertEquals("1", $pr->body->error_code, "error code is not correct (invalid session hash passed)[new pending game]");
     // add a second pending game fo the same user and check that the system dodn't match the games since they belong to the same user!
     $p->body->session = $session;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $p->body->session = $session;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->AssertEquals(0, game::getNumberOfGames(), "one pending games with the same size added[new pending game]");
     $p->body->session = $session2;
     $req = $p->asXML();
     $obj = new XmlParseRequest();
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->assertEquals("5", $pr->body->id, "[new pending game]");
     $this->assertEquals($session2, $pr->body->session, "[new pending game]");
     $this->AssertEquals(1, game::getNumberOfGames(), "two pending games with the same size added[new pending game]");
     $obj->processRequest($req);
     $response = $obj->getResponse();
     $pr = simplexml_load_string($response);
     $this->assertEquals("successful", $pr->body->status, "[new pending game]");
     $this->assertEquals("5", $pr->body->id, "[new pending game]");
     $this->assertEquals($session2, $pr->body->session, "[new pending game]");
     $this->AssertEquals(2, game::getNumberOfGames(), "two pending games with the same size added[new pending game]");
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:79,代码来源:ParseRequestTest.php

示例4: test

 public function test()
 {
     $username = "howdy";
     $password = "123456";
     $email = "gg@gmail.com";
     $username2 = "bla2";
     $password2 = "pass2";
     $email2 = "gr@gmmail.com";
     $username3 = "gue";
     $password3 = "pass3";
     $email3 = "eee@gmail.com";
     user::create_new_user($username, $password, $email);
     $this->assertEquals(1, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username2, $password2, $email2);
     $this->assertEquals(2, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     user::create_new_user($username3, $password3, $email3);
     $this->assertEquals(3, user::getNumberOfUsers(), "number of users is not correct after adding a new user");
     $user1ID = user::getUserByUsername($username)['id'];
     $user2ID = user::getUserByUsername($username2)['id'];
     $user3ID = user::getUserByUsername($username3)['id'];
     //pending_game::add_new_pending_game($user_id,$size) ;
     //pending_game::get_pending_game_by_id($id) ;
     $this->assertFalse(pending_game::add_new_pending_game($user1ID, -1), "[pending_game::add_new_pending_game()]");
     $this->assertFalse(pending_game::add_new_pending_game("sdfdsf", 3), "[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $pg_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $pg_info = pending_game::get_pending_game_by_id($pg_id);
     $this->assertEquals(3, $pg_info['size'], '[pending_game::add_new_pending_game()]');
     $this->assertEquals($user1ID, $pg_info['userID'], '[pending_game::add_new_pending_game()]');
     //get_all_pending_games_for_user_id($user_id)
     $this->assertEquals(1, count(pending_game::get_all_pending_games_for_user_id($user1ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertEquals(2, count(pending_game::get_all_pending_games_for_user_id($user1ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertNull(pending_game::get_all_pending_games_for_user_id("hhh"), "[get_all_pending_games_for_user_id()]");
     $this->assertNull(pending_game::get_all_pending_games_for_user_id($user3ID), "[get_all_pending_games_for_user_id()]");
     $this->assertEquals($user1ID, pending_game::get_all_pending_games_for_user_id($user1ID)[0]['userID'], "[get_all_pending_games_for_user_id()]");
     //get_all_pending_games_by_size($size)
     pending_game::clear_table();
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $pg_id1 = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertEquals(2, count(pending_game::get_all_pending_games_by_size(3)), "[get_all_pending_games_by_size()]");
     $this->assertEquals(1, count(pending_game::get_all_pending_games_by_size(4)), "[get_all_pending_games_by_size()]");
     $this->assertNull(pending_game::get_all_pending_games_by_size(5), "[get_all_pending_games_by_size()]");
     //get_all_pending_games()
     $this->assertEquals(3, count(pending_game::get_all_pending_games()), "[get_all_pending_games()]");
     //get_count_pending_games()
     $this->assertEquals(3, pending_game::get_count_pending_games(), "[get_count_pending_games()]");
     //get_count_pending_by_size($size)
     $this->assertEquals(0, pending_game::get_count_pending_by_size(10), "[get_count_pending_by_size()]");
     $this->assertEquals(0, pending_game::get_count_pending_by_size("sdfdf"), "[get_count_pending_by_size()]");
     $this->assertEquals(2, pending_game::get_count_pending_by_size(3), "[get_count_pending_by_size()]");
     $this->assertEquals(1, pending_game::get_count_pending_by_size(4), "[get_count_pending_by_size()]");
     //pending_game::delete_pending_game_by_id($id)
     $this->assertFalse(pending_game::delete_pending_game_by_id("sds"), "[pending_game::delete_pending_game_by_id()]");
     $this->assertEquals($pg_id1, pending_game::get_pending_game_by_id($pg_id1)['id'], "[delete_pending_game_by_id()]");
     $this->assertTrue(pending_game::delete_pending_game_by_id($pg_id1), "[pending_game::delete_pending_game_by_id()]");
     $this->assertNull(pending_game::get_pending_game_by_id($pg_id1), "[delete_pending_game_by_id()]");
     //pending_game::delete_all_pending_games_for_user_id($user_id)
     $this->assertFalse(pending_game::delete_all_pending_games_for_user_id("ddd"), "[pending_game::delete_all_pending_games_for_user_id()]");
     pending_game::clear_table();
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $this->assertEquals(2, count(pending_game::get_all_pending_games_for_user_id($user1ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertEquals(3, pending_game::get_count_pending_games(), "[get_count_pending_games()]");
     $this->assertTrue(pending_game::delete_all_pending_games_for_user_id($user1ID), "[pending_game::delete_all_pending_games_for_user_id()]");
     $this->assertEquals(1, pending_game::get_count_pending_games(), "[get_count_pending_games()]");
     $this->assertEquals(1, count(pending_game::get_all_pending_games_for_user_id($user2ID)), "[get_all_pending_games_for_user_id()]");
     $this->assertNull(pending_game::get_all_pending_games_for_user_id($user1ID), "[get_all_pending_games_for_user_id()]");
     //pending_game::match($game_id1,$game_id2)
     pending_game::clear_table();
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 3), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g1_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user2ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g2_id = pending_game::$last_inserted_id;
     $this->assertTrue(pending_game::add_new_pending_game($user1ID, 4), "failed to add new pending_game[pending_game::add_new_pending_game()]");
     $g3_id = pending_game::$last_inserted_id;
     $this->assertFalse(pending_game::match($g1_id, $g2_id));
     $this->assertFalse(pending_game::match("d", $g2_id));
     $this->assertFalse(pending_game::match($g1_id, "d"));
     $this->assertEquals(0, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(2, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertTrue(pending_game::match($g3_id, $g2_id));
     $this->assertEquals(1, game::getNumberOfGames(), "[pending_game::mathc()]");
     $this->assertEquals(0, pending_game::get_count_pending_by_size(4), "[pending_game::mathc()]");
     $this->assertTrue(!empty(game::getAllGamesForUserId($user1ID)), "[pending_game::mathc()]");
     $this->assertTrue(!empty(game::getAllGamesForUserId($user2ID)), "[pending_game::mathc()]");
 }
开发者ID:uunuu,项目名称:dot_boxes,代码行数:91,代码来源:table_pending_gameTest.php


注:本文中的game::getNumberOfGames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。