/**
 * Create a Fleet instance
 * It will persist the instance in $_SESSION super global
 *
 * @return Fleet|mixed
 */
function getFleet()
{
    // Reset the session
    if (isset($_GET['reset'])) {
        unset($_SESSION['fleet']);
    }
    if (isset($_SESSION['fleet'])) {
        $fleet = unserialize($_SESSION['fleet']);
        return $fleet;
    } else {
        $fleet = new Fleet();
        $fleet->addShip(new Destroyer('d1'));
        $fleet->addShip(new Destroyer('d2'));
        $fleet->addShip(new Battleship('b1'));
        $fleet->deploy();
        $_SESSION['fleet'] = serialize($fleet);
        return $fleet;
    }
}
 public function test_ship_is_sunk()
 {
     $fleet = new Fleet();
     $fleet->addShip(new Destroyer('d1'));
     $fleet->setDirection('horizontal');
     $fleet->setRow('a');
     $fleet->setColumn(1);
     $fleet->deploy();
     $fleet->fire('a', 1);
     $fleet->fire('a', 2);
     $fleet->fire('a', 3);
     $fleet->fire('a', 4);
     $ship = $fleet->getShip('d1');
     $shipStatus = $ship->getStatus();
     $this->assertEquals('sunk', $shipStatus, 'Ship should be completely sunk but it is only ' . $shipStatus);
     $fleetStatus = $fleet->getStatus();
     $this->assertEquals('sunk', $fleetStatus, 'Expected Fleet to be sunk but instead got ' . $fleetStatus);
 }