/** * @param HHPnet\Core\Application\Services\Songs\SaveSong\SaveSongRequest $request * @param HHPnet\Core\Domain\Albums\AlbumId $album_id */ public function it_is_not_possible_to_register_a_given_song_twice(SaveSongRequest $request, 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(true); $this->shouldThrow('\\DomainException')->during('execute', array($request)); }
/** * @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); }