/**
  * @param $browser
  * @param $device
  * @param null $dateString
  * @param int $views
  * @return $this
  */
 public function createView($browser, $device, $dateString = null, $views = 1)
 {
     $date = $dateString ? new \DateTime($dateString) : new \DateTime('now');
     $view = new View();
     $view->setId(uniqid());
     $view->setBrowser($browser);
     $view->setDevice($device);
     $view->setViews($views);
     $view->setDate($date);
     $tags = array();
     $tags[] = new Tag("vip", 4.0);
     $tags[] = new Tag("new", 3.0);
     $view->setTags($tags);
     $this->type->addDocument(new \Elastica\Document("", $view->toArray()));
     return $this;
 }
 public function testUpdate()
 {
     $searchManager = $this->getSearchManager();
     $viewRepo = $searchManager->getRepository(View::class);
     $view = new View();
     $view->setId(uniqid());
     $view->setBrowser('safari');
     $view->setDevice('ios');
     $view->setViews(10);
     $view->setTags(array(new Tag('pro', 10.0)));
     $view->setDate(new \DateTime('c'));
     $viewRepo->save($view, true);
     $views = $viewRepo->findBy(array('browser' => 'safari', 'device' => 'ios'));
     /** @var View $view */
     $view = $views->first();
     $id = $view->getId();
     $this->assertSame($view->getBrowser(), 'safari', $this->debug($view));
     $this->assertSame($view->getDevice(), 'ios', $this->debug($view));
     $view->setBrowser('firefox');
     $viewRepo->save($view, true);
     $view = $viewRepo->findOneBy(array('browser' => 'firefox'));
     $this->assertSame($id, $view->getId(), $this->debug($view));
 }