/**
  * @see GameInitiationResponse::addBattlefield()
  * @test
  */
 public function addBattlefield()
 {
     $game = MockFactory::getGameMock();
     $game->getBattlefields()[0]->setPlayer(MockFactory::getAIPlayerMock(''))->getCellByCoordinate('A1')->setFlags(CellModel::FLAG_SHIP);
     $request = new GameInitiationResponse($game->getBattlefields());
     foreach ($request->getBattlefields() as $battlefield) {
         foreach ($battlefield->getCells() as $cell) {
             if (PlayerModel::isAIControlled($battlefield->getPlayer())) {
                 $this->assertEquals(CellModel::FLAG_NONE, $cell->getFlags());
             }
         }
     }
 }
 /**
  * should:
  *      generate X battlefields of Y size
  *      assign AI controlled player to the generated battlefield
  *      initiate ship cells for the generated battlefield
  *      attach generated battlefield to the Game
  *
  * @see GameBuilder::attachAIBattlefields
  * @test
  */
 public function attachAIBattlefields()
 {
     $game = MockFactory::getGameMock(0, 0);
     $this->invokeMethod(static::$gameBuilder, 'attachAIBattlefields', [$game, 2, 7]);
     $this->assertCount(2, $game->getBattlefields());
     foreach ($game->getBattlefields() as $battlefield) {
         $this->assertCount(49, $battlefield->getCells());
         $this->assertTrue(PlayerModel::isAIControlled($battlefield->getPlayer()));
         $this->assertTrue(BattlefieldModel::hasUnfinishedShips($battlefield));
         foreach ($battlefield->getCells() as $coordinate => $cell) {
             /** all battlefields associated with AI players currently have hardcoded ship into B2 cell */
             $expectedFlag = 'B2' === $coordinate ? CellModel::FLAG_SHIP : CellModel::FLAG_NONE;
             $this->assertEquals($expectedFlag, $cell->getFlags());
         }
     }
 }
 /**
  * invoke game processing method to Win Game
  *
  * @see     GameProcessor::processTurn
  * @test
  *
  * @depends processTurnToNotWin
  */
 public function processTurnToWin()
 {
     $game = MockFactory::getGameMock();
     /** to make sure CPU will never win from one turn. */
     $game->getBattlefields()[0]->getCellByCoordinate('A1')->addFlag(CellModel::FLAG_SHIP);
     $game->getBattlefields()[0]->getCellByCoordinate('A2')->addFlag(CellModel::FLAG_SHIP);
     $game->getBattlefields()[1]->setPlayer(MockFactory::getAIPlayerMock(''));
     $game->getBattlefields()[1]->getCellByCoordinate('A1')->addFlag(CellModel::FLAG_SHIP);
     $game = static::$gameProcessor->processTurn($game->getBattlefields()[1]->getCellByCoordinate('A1'));
     $this->assertNotNull($game->getResult());
     $this->assertInstanceOf(GameResult::class, $game->getResult());
 }
 /**
  * @see          GameTurnResponse::setCells
  * @test
  *
  * @dataProvider setCellsProvider
  *
  * @param Cell[] $cells
  */
 public function setCellsOnExternalCall(array $cells)
 {
     $response = new GameTurnResponse(MockFactory::getGameMock(), []);
     $response->setCells($cells);
     $this->iterateResponseCells($response);
 }