/** * @param HHPnet\Core\Application\Services\Songs\SaveSongRequest $request * * @return HHPnet\Core\Application\Services\Songs\SaveSongResponse */ public function execute(SaveSongRequest $request) { try { $this->repository->getBySongByName($request->albumId(), $request->name()); throw new \DomainException('Given song has been registered in our database'); } catch (\UnexpectedValueException $e) { } $song = $this->repository->save($this->factory->getSongEntity(null, $request->albumId(), $request->name(), $request->type(), $request->path())); return new SaveSongResponse($song); }
/** * @param HHPnet\Core\Application\Services\Songs\SaveSong\SaveSongRequest $request * @param HHPnet\Core\Domain\Songs\Song $song * @param HHPnet\Core\Domain\Albums\AlbumId $album_id */ public function it_is_possible_to_save_a_new_song(SaveSongRequest $request, Song $song, AlbumId $album_id) { $request->albumId()->willReturn($album_id); $request->name()->willReturn('name'); $request->type()->willReturn('type'); $request->path()->willReturn('path'); $this->factory->getSongEntity(null, $album_id, 'name', 'type', 'path')->willReturn($song); $this->repository->getBySongByName($album_id, 'name')->willThrow('\\UnexpectedValueException'); $this->repository->save($song)->willReturn($song); $this->execute($request)->shouldHaveType('HHPnet\\Core\\Application\\Services\\Songs\\SaveSong\\SaveSongResponse'); }
/** * @param HHPnet\Core\Application\Services\Songs\GetSong\GetSongRequest $request */ public function it_is_not_possible_to_get_a_non_existing_song(GetSongRequest $request) { $request->songId()->willReturn(1); $this->repository->getById(1)->willThrow('\\UnexpectedValueException'); $this->shouldThrow('\\UnexpectedValueException')->during('execute', array($request)); }
/** * @param HHPnet\Core\Application\Services\Songs\GetSongRequest $request * * @return HHPnet\Core\Application\Services\Songs\GetSongResponse */ public function execute(GetSongRequest $request) { return new GetSongResponse($this->repository->getById($request->songId())); }