/** * @Transform /^channel "([^"]+)"$/ * @Transform /^"([^"]+)" channel/ * @Transform :channel */ public function getChannelByName($channelName) { $channel = $this->channelRepository->findOneByName($channelName); if (null === $channel) { throw new \InvalidArgumentException('Channel with name "' . $channelName . '" does not exist'); } return $channel; }
/** * @Transform /^channel "([^"]+)"$/ * @Transform /^"([^"]+)" channel/ * @Transform /^channel to "([^"]+)"$/ * @Transform :channel */ public function getChannelByName($channelName) { $channel = $this->channelRepository->findOneByName($channelName); Assert::notNull($channel, sprintf('Channel with name "%s" does not exist', $channelName)); return $channel; }
function it_throws_an_exception_if_channel_is_not_found(ChannelRepositoryInterface $channelRepository) { $channelRepository->findOneByName('Store')->willReturn(null); $this->shouldThrow(new \InvalidArgumentException('Channel with name "Store" does not exist'))->during('getChannelByName', ['Store']); }