/** * {@inheritdoc} */ public function transform($value) { if (!is_array($value)) { throw new UnexpectedTypeException($value, 'array'); } if (empty($value)) { return new ArrayCollection(); } return new ArrayCollection($this->taxonRepository->findBy(['code' => $value['taxons']])); }
function it_transforms_only_existing_taxons(TaxonRepositoryInterface $taxonRepository, TaxonInterface $bows) { $taxonRepository->findBy(['code' => ['bows', 'swords']])->willReturn([$bows]); $taxons = new ArrayCollection([$bows->getWrappedObject()]); $this->transform(['taxons' => ['bows', 'swords']])->shouldBeCollection($taxons); }