/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $choiceList = function (Options $options) { if (isset($options['subject'])) { $methods = $this->resolver->getSupportedMethods($options['subject'], $options['criteria']); } else { $methods = $this->repository->findBy($options['criteria']); } return new ObjectChoiceList($methods, null, [], null, 'id'); }; $resolver->setDefaults(['choice_list' => $choiceList, 'criteria' => []])->setDefined(['subject'])->setAllowedTypes('subject', ShippingSubjectInterface::class)->setAllowedTypes('criteria', 'array'); }
function it_uses_registry_to_provide_shipping_methods_for_shipping_subject(MethodsResolverInterface $firstMethodsResolver, MethodsResolverInterface $secondMethodsResolver, PrioritizedServiceRegistryInterface $resolversRegistry, ShippingMethodInterface $shippingMethod, ShippingSubjectInterface $shippingSubject) { $resolversRegistry->all()->willReturn([$firstMethodsResolver, $secondMethodsResolver]); $firstMethodsResolver->supports($shippingSubject)->willReturn(false); $secondMethodsResolver->supports($shippingSubject)->willReturn(true); $secondMethodsResolver->getSupportedMethods($shippingSubject)->willReturn([$shippingMethod]); $this->getSupportedMethods($shippingSubject)->shouldReturn([$shippingMethod]); }