diff --git a/src/engine/BMInterface.php b/src/engine/BMInterface.php index 925cbf784..b3cf2a994 100644 --- a/src/engine/BMInterface.php +++ b/src/engine/BMInterface.php @@ -924,8 +924,9 @@ protected function recreate_optRequestArrayArray($game) { * Save game to database * * @param BMGame $game + * @param int $expectedPrevState */ - protected function save_game(BMGame $game) { + protected function save_game(BMGame $game, int $expectedPrevState) { // force game to proceed to the latest possible before saving $game->proceed_to_next_user_action(); @@ -933,6 +934,8 @@ protected function save_game(BMGame $game) { self::$conn->beginTransaction(); try { + $prevGame = $this->load_game_parameters($game->gameId, FALSE); + assert($prevGame->gameState == $expectedPrevState, "DB game state changed between load and save"); $this->resolve_random_button_selection($game); $this->save_basic_game_parameters($game); $this->save_button_recipes($game); diff --git a/src/engine/BMInterfaceGame.php b/src/engine/BMInterfaceGame.php index c70074259..bf95c3e5b 100644 --- a/src/engine/BMInterfaceGame.php +++ b/src/engine/BMInterfaceGame.php @@ -87,6 +87,7 @@ public function create_game( // update game state to latest possible $game = $this->load_game($gameId, NULL, TRUE); + $prevState = $game->gameState; if (!($game instanceof BMGame)) { throw new UnexpectedValueException( "Could not load newly-created game $gameId" @@ -103,7 +104,7 @@ public function create_game( $chatNotice = '[i]Continued from [game=' . $previousGameId . '][i]'; $game->add_chat(-1, $chatNotice); } - $this->save_game($game); + $this->save_game($game, $prevState); $this->set_message("Game $gameId created successfully."); return array('gameId' => $gameId); @@ -560,6 +561,7 @@ public function save_join_game_decision($playerId, $gameId, $decision) { } $game = $this->load_game($gameId); + $prevState = $game->gameState; if (BMGameState::CHOOSE_JOIN_GAME != $game->gameState) { if (('reject' == $decision) && @@ -596,7 +598,7 @@ public function save_join_game_decision($playerId, $gameId, $decision) { $game->gameState = BMGameState::CANCELLED; } - $this->save_game($game); + $this->save_game($game, $prevState); if ($decisionFlag) { $this->set_message("Joined game $gameId"); @@ -659,9 +661,10 @@ public function join_open_game($currentPlayerId, $gameId) { self::$db->update($query, $parameters); $game = $this->load_game($gameId); + $prevState = $game->gameState; $player = $game->playerArray[$emptyPlayerIdx]; $player->hasPlayerAcceptedGame = TRUE; - $this->save_game($game); + $this->save_game($game, $prevState); $this->set_message('Successfully joined game ' . $gameId); return TRUE; @@ -684,6 +687,7 @@ public function join_open_game($currentPlayerId, $gameId) { public function cancel_open_game($currentPlayerId, $gameId) { try { $game = $this->load_game($gameId); + $prevState = $game->gameState; // check that the current player is involved in this game $isPlayerInThisGame = ($game->playerArray[0]->playerId == $currentPlayerId); @@ -706,7 +710,7 @@ public function cancel_open_game($currentPlayerId, $gameId) { $game->gameState = BMGameState::CANCELLED; - $this->save_game($game); + $this->save_game($game, $prevState); $this->set_message("Successfully cancelled game $gameId"); return TRUE; @@ -785,7 +789,8 @@ public function select_button( self::$db->update($query, $parameters); $game = $this->load_game($gameId); - $this->save_game($game); + $prevState = $game->gameState; + $this->save_game($game, $prevState); return TRUE; } catch (Exception $e) { @@ -816,6 +821,7 @@ public function submit_die_values( ) { try { $game = $this->load_game($gameId); + $prevState = $game->gameState; $currentPlayerIdx = array_search($playerId, $game->playerIdArray); // check that the timestamp and the game state are correct, and that @@ -875,7 +881,7 @@ public function submit_die_values( if ((FALSE == $game->playerArray[$currentPlayerIdx]->waitingOnAction) || ($game->gameState > BMGameState::SPECIFY_DICE) || ($game->roundNumber > $roundNumber)) { - $this->save_game($game); + $this->save_game($game, $prevState); $this->set_message('Successfully set die sizes'); return TRUE; } else { @@ -967,6 +973,7 @@ protected function set_option_values($optionValueArray, $currentPlayerIdx, $game public function submit_turn($args) { try { $game = $this->load_game($args['game']); + $prevState = $game->gameState; if (!$this->is_action_current( $game, @@ -1024,7 +1031,7 @@ public function submit_turn($args) { return NULL; } - $this->save_game($game); + $this->save_game($game, $prevState); // On success, don't set a message, because one will be set from the action log return TRUE; @@ -1151,6 +1158,7 @@ public function react_to_auxiliary( $this->set_message('Invalid game'); return FALSE; } + $prevState = $game->gameState; if (!$this->is_action_current( $game, BMGameState::CHOOSE_AUXILIARY_DICE, @@ -1204,7 +1212,7 @@ public function react_to_auxiliary( $this->set_message('Invalid response to auxiliary choice.'); return FALSE; } - $this->save_game($game); + $this->save_game($game, $prevState); return TRUE; } catch (Exception $e) { error_log( @@ -1264,6 +1272,7 @@ public function react_to_reserve( ) { try { $game = $this->load_game($gameId); + $prevState = $game->gameState; if (!$this->is_action_current( $game, BMGameState::CHOOSE_RESERVE_DICE, @@ -1308,7 +1317,7 @@ public function react_to_reserve( return FALSE; } - $this->save_game($game); + $this->save_game($game, $prevState); return TRUE; } catch (Exception $e) { @@ -1368,6 +1377,7 @@ public function react_to_initiative( ) { try { $game = $this->load_game($gameId); + $prevState = $game->gameState; if (!$this->is_action_current( $game, BMGameState::REACT_TO_INITIATIVE, @@ -1412,7 +1422,7 @@ public function react_to_initiative( $isSuccessful = $game->react_to_initiative($argArray); if ($isSuccessful) { - $this->save_game($game); + $this->save_game($game, $prevState); if ($isSuccessful['gainedInitiative']) { $this->set_message('Successfully gained initiative'); @@ -1480,6 +1490,7 @@ public function adjust_fire( ) { try { $game = $this->load_game($gameId); + $prevState = $game->gameState; if (!$this->is_action_current( $game, BMGameState::ADJUST_FIRE_DICE, @@ -1540,7 +1551,7 @@ public function adjust_fire( ); } - $this->save_game($game); + $this->save_game($game, $prevState); } else { $this->set_message('Invalid fire turndown'); } diff --git a/test/src/engine/BMInterfaceGameTest.php b/test/src/engine/BMInterfaceGameTest.php index d03b03d09..b488c2cf7 100644 --- a/test/src/engine/BMInterfaceGameTest.php +++ b/test/src/engine/BMInterfaceGameTest.php @@ -397,7 +397,7 @@ public function test_create_game_with_one_random_button_and_one_unspecified() { $this->assertEmpty($game->playerArray[1]->button); $this->assertFalse($game->playerArray[1]->isButtonChoiceRandom); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEmpty($game->playerArray[0]->button); $this->assertTrue($game->playerArray[0]->isButtonChoiceRandom); @@ -1088,7 +1088,7 @@ public function test_react_to_reserve_decline() { $playerArray[1]->activeDieArray = array(); $game->playerArray = $playerArray; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::CHOOSE_RESERVE_DICE, $game->gameState); @@ -1175,7 +1175,7 @@ public function test_react_to_reserve_add() { $playerArray[1]->activeDieArray = array(); $game->playerArray = $playerArray; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::CHOOSE_RESERVE_DICE, $game->gameState); @@ -1256,7 +1256,7 @@ function test_fire() { $game->swingValueArrayArray = array(array('X' => 17), array('X' => 5)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -1298,7 +1298,7 @@ function test_fire() { array(0), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(TRUE, FALSE), $game->waitingOnActionArray); diff --git a/test/src/engine/BMInterfaceTest.php b/test/src/engine/BMInterfaceTest.php index 9b01c9617..f56e7a28b 100644 --- a/test/src/engine/BMInterfaceTest.php +++ b/test/src/engine/BMInterfaceTest.php @@ -26,7 +26,7 @@ public function test_load_game_after_setting_swing_values() { $this->assertEquals(BMGameState::SPECIFY_DICE, $game->gameState); // specify swing dice correctly $game->swingValueArrayArray = array(array('X' => 19), array('X' => 5)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // check player info @@ -147,7 +147,7 @@ public function test_play_turn() { $player = $game->playerArray[1]; $player->swingValueArray = array('X' => 8); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // artificially set die values @@ -165,7 +165,7 @@ public function test_play_turn() { $game->activePlayerIdx = 1; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $game->attack = array(1, // attackerPlayerIdx @@ -174,7 +174,7 @@ public function test_play_turn() { array(1), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -205,7 +205,7 @@ public function test_load_poison() { // specify swing dice correctly $game->swingValueArrayArray = array(array('V'=>11), array('V'=>7)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // artificially set die values @@ -223,7 +223,7 @@ public function test_load_poison() { $game->activePlayerIdx = 0; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(array(-2.5, 9.5), $game->roundScoreArray); @@ -234,7 +234,7 @@ public function test_load_poison() { array(0), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -359,7 +359,7 @@ public function test_swing_value_reset_at_end_of_round() { $this->assertEquals(array('V'), array_keys($game->swingValueArrayArray[1])); $this->assertEquals(11, $game->swingValueArrayArray[1]['V']); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(array('X'), array_keys($game->swingValueArrayArray[0])); @@ -380,7 +380,7 @@ public function test_swing_value_reset_at_end_of_round() { array(1), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // artificially set die values @@ -399,7 +399,7 @@ public function test_swing_value_reset_at_end_of_round() { $this->assertEquals(array('V'), array_keys($game->swingValueArrayArray[1])); $this->assertEquals(11, $game->swingValueArrayArray[1]['V']); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(array(array('W' => 0, 'L' => 1, 'D' => 0), @@ -449,12 +449,12 @@ public function test_swing_value_reset_at_end_of_game() { $game->buttonArray = array($button1, $button2); $game->waitingOnActionArray = array(FALSE, FALSE); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // specify swing dice correctly $game->swingValueArrayArray = array(array('X' => 7), array('V' => 11)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // artificially set player 1 as winning initiative @@ -476,7 +476,7 @@ public function test_swing_value_reset_at_end_of_game() { array(0), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(BMGameState::END_GAME, $game->gameState); @@ -561,7 +561,7 @@ public function test_swing_value_persistence() { $dieArrayArray[0][1] = $newDie; $game->activeDieArrayArray = $dieArrayArray; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(array('X' => 7), array('V' => 11)), @@ -629,7 +629,7 @@ public function test_all_pass() { $game->gameScoreArrayArray); $this->assertEquals(1, $game->nRecentPasses); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -699,14 +699,14 @@ public function test_autopass() { $game->activePlayerIdx = 0; $game->waitingOnActionArray = array(TRUE, FALSE); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // player 1 performs skill attack, player 2 autopasses $game->attack = array(0, 1, array(0, 4), array(0), 'Skill'); $game->proceed_to_next_user_action(); $this->assertCount(4, $game->activeDieArrayArray[1]); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -718,10 +718,10 @@ public function test_autopass() { // player 1 passes $game->attack = array(0, 1, array(), array(), 'Pass'); $game->proceed_to_next_user_action(); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); $game->swingValueArrayArray = array(array('X' => 4), array('X' => 20)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($gameId); // should now be at the beginning of round 2 @@ -759,7 +759,7 @@ function test_twin_die() { // specify swing dice correctly $game->swingValueArrayArray = array(array(), array('V' => 11)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertTrue($game->activeDieArrayArray[1][3]->dice[0] instanceof BMDieSwing); @@ -825,7 +825,7 @@ function test_twin_die() { array(3), // defenderAttackDieIdxArray 'Shadow'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(FALSE, TRUE), $game->waitingOnActionArray); @@ -909,7 +909,7 @@ function test_konstant() { array(0), // defenderAttackDieIdxArray 'Skill'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(FALSE, TRUE), $game->waitingOnActionArray); @@ -966,7 +966,7 @@ public function test_surrender() { array(1), // defenderAttackDieIdxArray 'Surrender'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(1, $game->activePlayerIdx); @@ -988,7 +988,7 @@ public function test_surrender() { array(), // defenderAttackDieIdxArray 'Surrender'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(1, $game->activePlayerIdx); @@ -1010,7 +1010,7 @@ public function test_surrender() { array(), // defenderAttackDieIdxArray 'Surrender'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -1056,7 +1056,7 @@ public function test_autoplay_bug() { $game->activeDieArrayArray = array(array(), array()); $game->gameState = BMGameState::START_GAME; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(TRUE, FALSE), $game->waitingOnActionArray); @@ -1078,7 +1078,7 @@ public function test_autoplay_bug() { array(2), // defenderAttackDieIdxArray 'Skill'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(FALSE, TRUE), $game->waitingOnActionArray); @@ -1101,7 +1101,7 @@ public function test_autoplay_bug() { array(0), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(TRUE, FALSE), $game->waitingOnActionArray); @@ -1124,7 +1124,7 @@ public function test_autoplay_bug() { array(2), // defenderAttackDieIdxArray 'Skill'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(FALSE, TRUE), $game->waitingOnActionArray); @@ -1146,7 +1146,7 @@ public function test_autoplay_bug() { array(0), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(TRUE, FALSE), $game->waitingOnActionArray); @@ -1167,7 +1167,7 @@ public function test_autoplay_bug() { array(0), // defenderAttackDieIdxArray 'Skill'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(FALSE, TRUE), $game->waitingOnActionArray); @@ -1202,7 +1202,7 @@ public function test_reserve_swing_setting() { $this->assertEquals(BMGameState::SPECIFY_DICE, $game->gameState); $game->optValueArrayArray = array(array(1 => 5), array()); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -1226,7 +1226,7 @@ public function test_reserve_swing_setting() { // we should now be at the point where the bug triggers, at the stage of // loading the previous round's swing values - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(2, $game->roundNumber); @@ -1278,7 +1278,7 @@ public function test_echo_vs_other() { $this->assertEquals(0, $game->activeDieArrayArray[0][3]->originalPlayerIdx); $this->assertEquals(0, $game->activeDieArrayArray[0][4]->originalPlayerIdx); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals('(4) (4) (10) (12) (X)', $game->buttonArray[0]->recipe); @@ -1310,7 +1310,7 @@ public function test_echo_recipe_save() { $game->activeDieArrayArray = array(array(), array()); $game->gameState = BMGameState::START_GAME; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals('(V)', $game->buttonArray[0]->recipe); @@ -1339,7 +1339,7 @@ public function test_declined_courtesy_auxiliary_swing_dice() { // decline auxiliary dice $game->waitingOnActionArray = array(FALSE, FALSE); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::SPECIFY_DICE, $game->gameState); @@ -1352,7 +1352,7 @@ public function test_declined_courtesy_auxiliary_swing_dice() { $this->assertCount(5, $game->activeDieArrayArray[1]); $game->swingValueArrayArray = array(array(), array('X' => 5)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -1393,7 +1393,7 @@ public function test_option_game() { $player = $game->playerArray[0]; $player->optValueArray[2] = 6; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertTrue(is_null($game->activeDieArrayArray[0][2]->max)); @@ -1407,7 +1407,7 @@ public function test_option_game() { $this->assertEquals(array(array(2 => 12, 3 => 16, 4 => 20), array()), $game->optValueArrayArray); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(array(2 => 12, 3 => 16, 4 => 20), array()), @@ -1420,7 +1420,7 @@ public function test_option_game() { $this->assertEquals(16, $game->activeDieArrayArray[0][3]->max); $this->assertEquals(20, $game->activeDieArrayArray[0][4]->max); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::SPECIFY_DICE, $game->gameState); @@ -1479,7 +1479,7 @@ public function test_option_game() { array(2 => 8, 3 => 6, 4 => 12)), $game->optValueArrayArray); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(array(2 => 12, 3 => 16, 4 => 20), @@ -1551,7 +1551,7 @@ public function test_option_game() { array(0), // defenderAttackDieIdxArray 'Power'); // attackType - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(array(array('W' => 1, 'L' => 0, 'D' => 0), @@ -1618,7 +1618,7 @@ public function test_mood_swing_round() { // specify swing dice correctly $game->swingValueArrayArray = array(array('X' => 19), array('X' => 4)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertInstanceOf('BMDieSwing', $game->activeDieArrayArray[0][4]); @@ -1694,7 +1694,7 @@ public function test_mood_swing_round() { $game->proceed_to_next_user_action(); $preSaveMoodMax = $game->activeDieArrayArray[1][4]->max; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $postSaveMoodMax = $game->activeDieArrayArray[1][4]->max; $postSaveSwingSize = $game->activeDieArrayArray[1][4]->swingValue; @@ -1735,7 +1735,7 @@ public function test_twin_mood_swing_round() { // specify swing dice correctly $game->swingValueArrayArray = array(array('R' => 16), array('R' => 2)); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertTrue($game->activeDieArrayArray[0][4]->has_skill('Mood')); @@ -1829,7 +1829,7 @@ public function test_twin_mood_swing_round() { $game->proceed_to_next_user_action(); $preSaveMoodMax = $game->activeDieArrayArray[1][4]->max; - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $postSaveMoodMax = $game->activeDieArrayArray[1][4]->max; $postSaveSwingSize1 = $game->activeDieArrayArray[1][4]->dice[0]->swingValue; @@ -1864,7 +1864,7 @@ public function test_option_reset_bug() { $this->assertEquals(BMGameState::SPECIFY_DICE, $game->gameState); $game->optValueArrayArray = array(array(4 => 2), array()); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -1887,7 +1887,7 @@ public function test_option_reset_bug() { // capture the option die $game->attack = array(1, 0, array(0, 1), array(4), 'Skill'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -1900,7 +1900,7 @@ public function test_option_reset_bug() { $this->assertCount(4, $game->activeDieArrayArray[0]); $this->assertCount(4, $game->activeDieArrayArray[1]); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -1911,11 +1911,11 @@ public function test_option_reset_bug() { $this->assertCount(4, $game->activeDieArrayArray[0]); $this->assertCount(3, $game->activeDieArrayArray[1]); $game->attack = array(1, 0, array(), array(), 'Pass'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -1926,11 +1926,11 @@ public function test_option_reset_bug() { $this->assertCount(4, $game->activeDieArrayArray[0]); $this->assertCount(2, $game->activeDieArrayArray[1]); $game->attack = array(1, 0, array(), array(), 'Pass'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -1941,11 +1941,11 @@ public function test_option_reset_bug() { $this->assertCount(4, $game->activeDieArrayArray[0]); $this->assertCount(1, $game->activeDieArrayArray[1]); $game->attack = array(1, 0, array(), array(), 'Pass'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // we should now be at the point where the bug triggers, at end of round @@ -1981,7 +1981,7 @@ public function test_swing_reset_bug() { $this->assertEquals(BMGameState::SPECIFY_DICE, $game->gameState); $game->swingValueArrayArray = array(array('X' => 7), array()); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $this->assertEquals(BMGameState::START_TURN, $game->gameState); @@ -2004,7 +2004,7 @@ public function test_swing_reset_bug() { // capture a normal die $game->attack = array(1, 0, array(0, 1), array(0), 'Skill'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -2017,7 +2017,7 @@ public function test_swing_reset_bug() { $this->assertCount(4, $game->activeDieArrayArray[0]); $this->assertCount(4, $game->activeDieArrayArray[1]); $game->attack = array(0, 1, array(3), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -2029,7 +2029,7 @@ public function test_swing_reset_bug() { $this->assertCount(4, $game->activeDieArrayArray[0]); $this->assertCount(3, $game->activeDieArrayArray[1]); $game->attack = array(1, 0, array(0), array(3), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -2041,7 +2041,7 @@ public function test_swing_reset_bug() { $this->assertCount(3, $game->activeDieArrayArray[0]); $this->assertCount(3, $game->activeDieArrayArray[1]); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -2052,11 +2052,11 @@ public function test_swing_reset_bug() { $this->assertCount(3, $game->activeDieArrayArray[0]); $this->assertCount(2, $game->activeDieArrayArray[1]); $game->attack = array(1, 0, array(), array(), 'Pass'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // artificially set die value of rolled die @@ -2067,11 +2067,11 @@ public function test_swing_reset_bug() { $this->assertCount(3, $game->activeDieArrayArray[0]); $this->assertCount(1, $game->activeDieArrayArray[1]); $game->attack = array(1, 0, array(), array(), 'Pass'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); $game->attack = array(0, 1, array(0), array(0), 'Power'); - self::save_game($game); + self::save_game($game, $game->gameState); $game = self::load_game($game->gameId); // we should now be at the point where the bug triggers, at end of round diff --git a/test/src/engine/BMInterfaceTestAbstract.php b/test/src/engine/BMInterfaceTestAbstract.php index 850bedfb5..406e5139d 100644 --- a/test/src/engine/BMInterfaceTestAbstract.php +++ b/test/src/engine/BMInterfaceTestAbstract.php @@ -46,9 +46,9 @@ protected function load_game($gameId) { return $load_game->invokeArgs($this->object, array($gameId)); } - protected function save_game($game) { + protected function save_game($game, $prevState) { $save_game = self::getMethod('save_game'); - return $save_game->invokeArgs($this->object, array($game)); + return $save_game->invokeArgs($this->object, array($game, $prevState)); } protected function create_game_self_first(