/** * @param Request $request * @return JsonResponse */ public function indexJsonAction(Request $request) { $table = json_decode($request->get('table')); $request->get(PlayerInterface::SYMBOL_X) && $this->gameService->addPlayer($this->registryService->get($request->get(PlayerInterface::SYMBOL_X))); $request->get(PlayerInterface::SYMBOL_O) && $this->gameService->addPlayer($this->registryService->get($request->get(PlayerInterface::SYMBOL_O)), PlayerInterface::SYMBOL_O); $this->gameService->setTable($table); $this->gameService->getTurn(); return new JsonResponse(["status" => "ok", 'table' => $this->gameService->getTable(), 'winner' => $this->gameService->getWinner()]); }
/** * @expectedException \Exception * @expectedExceptionMessage Field is already filled */ public function testDoTurnOnExistingField() { $table = array_fill(0, 3, array_fill(0, 3, null)); $table[1][1] = PlayerInterface::SYMBOL_X; $game = new Game($table); $game->doTurn([1, 1], PlayerInterface::SYMBOL_X); $result = $game->getTable(); $this->assertEquals($table, $result); }