/** * {@inheritdoc} */ public function generate($name, $parentId = null) { $taxonSlug = Transliterator::transliterate($name); if (null === $parentId) { return $taxonSlug; } /** @var TaxonInterface $parent */ $parent = $this->taxonRepository->find($parentId); Assert::notNull($parent, sprintf('There is no parent taxon with id %d.', $parentId)); return $parent->getSlug() . self::SLUG_SEPARATOR . $taxonSlug; }
function it_throws_exception_if_parent_taxon_with_given_id_does_not_exist(TaxonRepositoryInterface $taxonRepository) { $taxonRepository->find(1)->willReturn(null); $this->shouldThrow(new \InvalidArgumentException('There is no parent taxon with id 1.'))->during('generate', ['Battle games', 1]); }