/** * @param HHPnet\Core\Application\Services\Videos\SaveVideo\SaveVideoRequest $request */ public function it_is_not_possible_to_register_a_given_video_twice(SaveVideoRequest $request) { $request->videoServiceId()->willReturn('video_service_id'); $request->videoService()->willReturn('video_service'); $request->title()->willReturn('title'); $request->description()->willReturn('description'); $this->factory->getVideoEntity(null, 'video_service_id', 'video_service', 'title', 'description')->willReturn(true); $this->shouldThrow('\\DomainException')->during('execute', array($request)); }
/** * @param HHPnet\Core\Application\Services\Videos\SaveVideo\SaveVideoRequest $request * * @return HHPnet\Core\Application\Services\Videos\SaveVideo\SaveVideoResponse */ public function execute(SaveVideoRequest $request) { try { $this->repository->getByVideoServiceId($request->videoServiceId(), $request->videoService()); throw new \DomainException('Given video has been registered in our database'); } catch (\UnexpectedValueException $e) { } $video = $this->repository->save($this->factory->getVideoEntity(null, $request->videoServiceId(), $request->videoService(), $request->title(), $request->description())); return new SaveVideoResponse($video); }
private function getVideoInstance($video_data) { if (is_null($video_data)) { throw new \UnexpectedValueException('Video not found in database'); } return $this->factory->getVideoEntity($video_data['_id'], $video_data['video_service_id'], $video_data['video_service'], $video_data['title'], $video_data['description']); }