Пример #1
0
 /**
  * {@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);
 }
 function it_uses_registry_to_provide_shipping_methods_for_shipping_subject(ShippingMethodsResolverInterface $firstMethodsResolver, ShippingMethodsResolverInterface $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]);
 }