function it_does_not_support_subject_if_none_of_resolvers_from_registry_supports_it(ShippingMethodsResolverInterface $firstMethodsResolver, ShippingMethodsResolverInterface $secondMethodsResolver, PrioritizedServiceRegistryInterface $resolversRegistry, ShippingSubjectInterface $shippingSubject) { $resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]); $firstMethodsResolver->supports($shippingSubject)->willReturn(false); $firstMethodsResolver->supports($shippingSubject)->willReturn(false); $this->supports($shippingSubject)->shouldReturn(false); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['choices' => function (Options $options) { if (isset($options['subject']) && $this->shippingMethodsResolver->supports($options['subject'])) { return $this->shippingMethodsResolver->getSupportedMethods($options['subject']); } return $this->repository->findAll(); }, 'choice_value' => 'code', 'choice_label' => 'name', 'choice_translation_domain' => false])->setDefined(['subject'])->setAllowedTypes('subject', ShippingSubjectInterface::class); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choiceList = function (Options $options) { if (isset($options['subject']) && $this->shippingMethodsResolver->supports($options['subject'])) { $methods = $this->shippingMethodsResolver->getSupportedMethods($options['subject']); } else { $methods = $this->repository->findAll(); } return new ObjectChoiceList($methods, null, [], null, 'code'); }; $resolver->setDefaults(['choice_list' => $choiceList])->setDefined(['subject'])->setAllowedTypes('subject', ShippingSubjectInterface::class); }