/**
  * Recibe el Accommodation que será insertado en la bd. Si el alojamiento no existe
  * lo inserta en la bd y devuelve el objeto. Si existe, lo devolverá null.
  *
  * @param  Accommodation $accom
  * @return Accommodation
  */
 public function createAccom(Accommodation $accom, $id)
 {
     $a = null;
     try {
         $a = AccommodationModel::create(['title' => $accom->getTitle(), 'desc' => $accom->getDesc(), 'capacity' => $accom->getCapacity(), 'beds' => $accom->getBeds(), 'bathrooms' => $accom->getBaths(), 'inside' => $accom->getInside(), 'outside' => $accom->getOutside(), 'price_per_person' => $accom->getPrice(), 'city' => $accom->getCity(), 'province' => $accom->getProvince(), 'user_id' => $id]);
         foreach ($accom->getPhotos() as $photo) {
             $this->addPhoto($photo, $a['id']);
         }
     } catch (QueryException $ex) {
         throw new \Exception("Ha fallado la inserción");
     }
     return $a;
 }
 /**
  * A basic functional test example.
  *
  * @return void
  * @group accomm
  */
 public function testAccommodation()
 {
     $accomm = new Accommodation();
     $p1 = new Photo();
     $p2 = new Photo();
     $arrayPhoto = [];
     $arrayPhoto2 = [];
     $p1->setUrl('url/photo1');
     $p1->setMain(0);
     $p2->setUrl('url/photo2');
     $p2->setMain(1);
     $arrayPhoto[] = $p1;
     $arrayPhoto[] = $p2;
     $arrayPhoto2[] = $p1;
     $arrayPhoto2[] = $p2;
     $this->assertEquals('El propietario aún no ha detallado nada sobre las características interiores del alojamiento.', $accomm->getInside());
     $this->assertEquals('El propietario aún no ha detallado nada sobre las características exteriores del alojamiento.', $accomm->getOutside());
     $accomm->setBaths(2);
     $accomm->setBeds(3);
     $accomm->setCapacity(5);
     $accomm->setCity('Elche');
     $accomm->setDesc('Alojamiento de lujo.');
     $accomm->setInside('Descripción del interior del alojamiento.');
     $accomm->setOutside('Descripción del exterior del alojamiento.');
     $accomm->setPhotos($arrayPhoto);
     $accomm->setPrice(50);
     $accomm->setProvince('Alicante');
     $accomm->setTitle('Casa rural');
     $this->assertEquals(2, $accomm->getBaths());
     $this->assertEquals(3, $accomm->getBeds());
     $this->assertEquals(5, $accomm->getCapacity());
     $this->assertEquals('Elche', $accomm->getCity());
     $this->assertEquals('Alojamiento de lujo.', $accomm->getDesc());
     $this->assertEquals('Descripción del interior del alojamiento.', $accomm->getInside());
     $this->assertEquals('Descripción del exterior del alojamiento.', $accomm->getOutside());
     $this->assertEquals(50, $accomm->getPrice());
     $this->assertEquals('Alicante', $accomm->getProvince());
     $this->assertEquals('Casa rural', $accomm->getTitle());
     $this->assertEquals($arrayPhoto2, $accomm->getPhotos());
 }