public function itSatisfiedBy(Map $map) { // Check for field status if ($map->getStatus() == 1) { return false; } // Check for number $countShips = 0; foreach (Ship::$ships as $shipType) { $countShips += $shipType['number']; } $alreadyLocated = $this->shipRepository->findOneBy(['player' => 1]); if ($alreadyLocated == $countShips) { return false; } // Check for location $lastLocated = $this->mapRepository->findOneBy(['player' => 1], ['id' => 'DESC']); if ($lastLocated->getXAxis() == $map->getXAxis()) { $key = array_search($lastLocated->getYAxis(), Map::$allowedYCoordinates); } elseif ($lastLocated->getYAxis() == $map->getYAxis()) { $key = array_search($lastLocated->getXAxis(), Map::$allowedXCoordinates); } else { return false; } return $this->checkPosition($map, $key); }
function it_can_not_locate_ship_cause_field_not_empty(Map $map, Ship $ship) { $map->getStatus()->willReturn(1); $this->itSatisfiedBy($map)->shouldReturn(false); }