/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setNormalizer('choices', function () { /** @var OrganizationInterface[] $organizations */ $organizations = $this->organizationRepository->findAvailable(); $choices = []; foreach ($organizations as $organization) { $choices[$organization->getName()] = $organization->getCode(); } return $choices; })->setDefaults(['invalid_message' => 'The selected organization does not exist']); }
public function it_defines_organization_choices(OptionsResolver $resolver, OrganizationRepositoryInterface $organizationRepository, OrganizationInterface $organization) { $organizationRepository->findAvailable()->willReturn([$organization]); $resolver->setNormalizer('choices', Argument::type('callable'))->willReturn($resolver); $resolver->setDefaults(['invalid_message' => 'The selected organization does not exist'])->shouldBeCalled(); $this->configureOptions($resolver); }