function it_calls_proper_factory_methods_based_on_configuration(RequestConfiguration $requestConfiguration, FactoryInterface $factory) { $requestConfiguration->getFactoryMethod()->willReturn('createNew'); $requestConfiguration->getFactoryArguments()->willReturn(['00032']); $factory->createNew('00032')->willReturn(['foo', 'bar']); $this->create($requestConfiguration, $factory)->shouldReturn(['foo', 'bar']); }
/** * @param string $name * * @return TaxonInterface */ private function createTaxon($name) { $taxon = $this->taxonFactory->createNew(); $taxon->setName($name); $taxon->setCode($this->getCodeFromName($name)); return $taxon; }
function it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_default_currency(RepositoryInterface $channelRepository, RepositoryInterface $countryRepository, RepositoryInterface $currencyRepository, RepositoryInterface $localeRepository, RepositoryInterface $zoneMemberRepository, RepositoryInterface $zoneRepository, ChannelFactoryInterface $channelFactory, FactoryInterface $countryFactory, FactoryInterface $currencyFactory, FactoryInterface $localeFactory, FactoryInterface $zoneFactory, FactoryInterface $zoneMemberFactory, ZoneMemberInterface $zoneMember, ZoneInterface $zone, ChannelInterface $channel, CountryInterface $unitedStates, CurrencyInterface $currency, LocaleInterface $locale) { $channel->getName()->willReturn('United States'); $channelFactory->createNamed('United States')->willReturn($channel); $localeFactory->createNew()->willReturn($locale); $locale->setCode('en_US')->shouldBeCalled(); $zoneMemberFactory->createNew()->willReturn($zoneMember); $zoneFactory->createNew()->willReturn($zone); $channel->setCode('WEB-US')->shouldBeCalled(); $channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled(); $zoneMember->setCode('US')->shouldBeCalled(); $zone->setCode('US')->shouldBeCalled(); $zone->setName('United States')->shouldBeCalled(); $zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled(); $zone->addMember($zoneMember)->shouldBeCalled(); $countryFactory->createNew()->willReturn($unitedStates); $unitedStates->setCode('US')->shouldBeCalled(); $currencyFactory->createNew()->willReturn($currency); $currency->setCode('USD')->shouldBeCalled(); $currency->setExchangeRate(1.0)->shouldBeCalled(); $channel->setDefaultCurrency($currency)->shouldBeCalled(); $channel->addCurrency($currency)->shouldBeCalled(); $channel->setDefaultLocale($locale)->shouldBeCalled(); $channel->addLocale($locale)->shouldBeCalled(); $currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null); $localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null); $currencyRepository->add($currency)->shouldBeCalled(); $localeRepository->add($locale)->shouldBeCalled(); $countryRepository->add($unitedStates)->shouldBeCalled(); $channelRepository->add($channel)->shouldBeCalled(); $zoneRepository->add($zone)->shouldBeCalled(); $zoneMemberRepository->add($zoneMember)->shouldBeCalled(); $this->create(); }
/** * @param string $name */ private function createCountryNamed($name) { /** @var CountryInterface $country */ $country = $this->countryFactory->createNew(); $country->setCode($this->getCountryCodeByEnglishCountryName($name)); $this->countryRepository->add($country); }
function it_creates_a_cart_item_and_assigns_a_product_variant(FactoryInterface $decoratedFactory, VariantResolverInterface $variantResolver, OrderItemInterface $cartItem, ProductInterface $product, ProductVariantInterface $productVariant) { $decoratedFactory->createNew()->willReturn($cartItem); $variantResolver->getVariant($product)->willReturn($productVariant); $cartItem->setVariant($productVariant)->shouldBeCalled(); $this->createForProduct($product)->shouldReturn($cartItem); }
/** * {@inheritdoc} */ public function generate(VariableInterface $variable) { if (!$variable->hasOptions()) { throw new \InvalidArgumentException('Cannot generate variants for an object without options.'); } $optionSet = array(); $optionMap = array(); foreach ($variable->getOptions() as $k => $option) { foreach ($option->getValues() as $value) { $optionSet[$k][] = $value->getId(); $optionMap[$value->getId()] = $value; } } $permutations = $this->setBuilder->build($optionSet); foreach ($permutations as $permutation) { $variant = $this->variantFactory->createNew(); $variant->setObject($variable); $variant->setDefaults($variable->getMasterVariant()); if (is_array($permutation)) { foreach ($permutation as $id) { $variant->addOption($optionMap[$id]); } } else { $variant->addOption($optionMap[$permutation]); } $variable->addVariant($variant); $this->process($variable, $variant); } }
/** * {@inheritdoc} */ public function createNew() { /** @var Route $route */ $route = $this->decoratedFactory->createNew(); $route->setParentDocument($this->documentManager->find(null, $this->routeParentPath)); return $route; }
/** * {@inheritdoc} */ public function createForPromotion(PromotionInterface $promotion) { Assert::true($promotion->isCouponBased(), sprintf('Promotion with name %s is not coupon based.', $promotion->getName())); $coupon = $this->factory->createNew(); $coupon->setPromotion($promotion); return $coupon; }
function it_calls_proper_method_with_arguments_based_on_configuration_when_creating_resource(FactoryInterface $factory, $configuration) { $configuration->getFactoryMethod('createNew')->willReturn('createNew'); $configuration->getFactoryArguments(array())->willReturn(array()); $factory->createNew()->willReturn(array('foo', 'bar')); $this->createResource($factory, 'createNew')->shouldReturn(array('foo', 'bar')); }
function it_creates_a_nth_order_rule(FactoryInterface $decoratedFactory, RuleInterface $rule) { $decoratedFactory->createNew()->willReturn($rule); $rule->setType(NthOrderRuleChecker::TYPE)->shouldBeCalled(); $rule->setConfiguration(['nth' => 10])->shouldBeCalled(); $this->createNthOrder(10)->shouldReturn($rule); }
function it_creates_a_taxon_and_assigns_a_taxonomy_to_id(FactoryInterface $factory, RepositoryInterface $taxonomyRepository, TaxonomyInterface $taxonomy, TaxonInterface $taxon) { $factory->createNew()->willReturn($taxon); $taxonomyRepository->find(13)->willReturn($taxonomy); $taxon->setTaxonomy($taxonomy)->shouldBeCalled(); $this->createForTaxonomy(13)->shouldReturn($taxon); }
function it_creates_a_contains_product_rule(FactoryInterface $decoratedFactory, PromotionRuleInterface $rule) { $decoratedFactory->createNew()->willReturn($rule); $rule->setType(ContainsProductRuleChecker::TYPE)->shouldBeCalled(); $rule->setConfiguration(['product_code' => 1])->shouldBeCalled(); $this->createContainsProduct(1)->shouldReturn($rule); }
/** * {@inheritdoc} */ public function createWithVariant() { $variant = $this->variantFactory->createNew(); $product = $this->factory->createNew(); $product->addVariant($variant); return $product; }
/** * @Given the store has disabled locale :localeCode */ public function theStoreHasDisabledLocale($localeCode) { $locale = $this->localeFactory->createNew(); $locale->setCode($localeCode); $locale->disable(); $this->saveLocale($locale); }
function it_creates_a_shipping_percentage_discount_action_with_a_given_discount_rate(FactoryInterface $decoratedFactory, PromotionActionInterface $promotionAction) { $decoratedFactory->createNew()->willReturn($promotionAction); $promotionAction->setType(ShippingPercentageDiscountPromotionActionCommand::TYPE)->shouldBeCalled(); $promotionAction->setConfiguration(['percentage' => 0.1])->shouldBeCalled(); $this->createShippingPercentageDiscount(0.1)->shouldReturn($promotionAction); }
/** * {@inheritdoc} */ public function createNew() { $taxon = $this->taxonFactory->createNew(); $taxonomy = $this->translatableFactory->createNew(); $taxonomy->setRoot($taxon); return $taxonomy; }
function it_creates_payment_with_currency_and_amout(FactoryInterface $paymentFactory, PaymentInterface $payment) { $paymentFactory->createNew()->willReturn($payment); $payment->setAmount(1234)->shouldBeCalled(); $payment->setCurrency('EUR')->shouldBeCalled(); $this->createWithAmountAndCurrency(1234, 'EUR'); }
/** * @param array $options * * @return FormView */ public function getItemFormView(array $options = array()) { $cartItem = $this->cartItemFactory->createNew(); $this->orderItemQuantityModifier->modify($cartItem, 1); $form = $this->formFactory->create('sylius_cart_item', $cartItem, $options); return $form->createView(); }
function it_creates_a_review_with_subject_and_reviewer(FactoryInterface $factory, ReviewableInterface $subject, ReviewInterface $review, ReviewerInterface $reviewer) { $factory->createNew()->willReturn($review); $review->setReviewSubject($subject)->shouldBeCalled(); $review->setAuthor($reviewer)->shouldBeCalled(); $this->createForSubjectWithReviewer($subject, $reviewer); }
function it_creates_new_product_with_variant(FactoryInterface $factory, FactoryInterface $variantFactory, ProductInterface $product, ProductVariantInterface $variant) { $variantFactory->createNew()->willReturn($variant); $factory->createNew()->willReturn($product); $product->addVariant($variant)->shouldBeCalled(); $this->createWithVariant()->shouldReturn($product); }
function it_creates_new_taxonomy_with_root(TaxonInterface $taxon, TaxonomyInterface $taxonomy, FactoryInterface $taxonFactory, TranslatableFactoryInterface $translatableFactory) { $taxonFactory->createNew()->shouldBeCalled()->willReturn($taxon); $translatableFactory->createNew()->shouldBeCalled()->willReturn($taxonomy); $taxonomy->setRoot($taxon)->shouldBeCalled(); $this->createNew()->shouldReturn($taxonomy); }
function it_creates_a_variant_and_assigns_a_product_to_id(FactoryInterface $factory, RepositoryInterface $productRepository, ProductInterface $product, VariantInterface $variant) { $factory->createNew()->willReturn($variant); $productRepository->find(13)->willReturn($product); $variant->setProduct($product)->shouldBeCalled(); $this->createForProduct(13)->shouldReturn($variant); }
/** * @param string $name */ private function createCountryNamed($name) { /** @var CountryInterface $country */ $country = $this->countryFactory->createNew(); $country->setCode($this->countryNameConverter->convertToCode($name)); $this->countryRepository->add($country); }
/** * {@inheritdoc} */ public function load($schemaAlias, $namespace = null, $ignoreUnknown = true) { /** @var SchemaInterface $schema */ $schema = $this->schemaRegistry->get($schemaAlias); /** @var SettingsResolverInterface $resolver */ $resolver = $this->resolverRegistry->get($schemaAlias); // try to resolve settings for schema alias and namespace $settings = $resolver->resolve($schemaAlias, $namespace); if (!$settings) { $settings = $this->settingsFactory->createNew(); $settings->setSchemaAlias($schemaAlias); } // We need to get a plain parameters array since we use the options resolver on it $parameters = $settings->getParameters(); $settingsBuilder = new SettingsBuilder(); $schema->buildSettings($settingsBuilder); // Remove unknown settings' parameters (e.g. From a previous version of the settings schema) if (true === $ignoreUnknown) { foreach ($parameters as $name => $value) { if (!$settingsBuilder->isDefined($name)) { unset($parameters[$name]); } } } $parameters = $settingsBuilder->resolve($parameters); $settings->setParameters($parameters); return $settings; }
function it_applies_percentage_discount_on_every_unit_in_order(FactoryInterface $adjustmentFactory, FilterInterface $priceRangeFilter, FilterInterface $taxonFilter, FilterInterface $productFilter, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $originalItems, Collection $units, OrderInterface $order, OrderItemInterface $orderItem1, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, PromotionInterface $promotion) { $order->getItems()->willReturn($originalItems); $originalItems->toArray()->willReturn([$orderItem1]); $priceRangeFilter->filter([$orderItem1], ['percentage' => 0.2])->willReturn([$orderItem1]); $taxonFilter->filter([$orderItem1], ['percentage' => 0.2])->willReturn([$orderItem1]); $productFilter->filter([$orderItem1], ['percentage' => 0.2])->willReturn([$orderItem1]); $orderItem1->getQuantity()->willReturn(2); $orderItem1->getUnits()->willReturn($units); $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()])); $orderItem1->getUnitPrice()->willReturn(500); $promotion->getName()->willReturn('Test promotion'); $promotion->getCode()->willReturn('TEST_PROMOTION'); $adjustmentFactory->createNew()->willReturn($promotionAdjustment1, $promotionAdjustment2); $promotionAdjustment1->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled(); $promotionAdjustment1->setLabel('Test promotion')->shouldBeCalled(); $promotionAdjustment1->setAmount(-100)->shouldBeCalled(); $promotionAdjustment1->setOriginCode('TEST_PROMOTION')->shouldBeCalled(); $promotionAdjustment2->setType(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->shouldBeCalled(); $promotionAdjustment2->setLabel('Test promotion')->shouldBeCalled(); $promotionAdjustment2->setAmount(-100)->shouldBeCalled(); $promotionAdjustment2->setOriginCode('TEST_PROMOTION')->shouldBeCalled(); $unit1->addAdjustment($promotionAdjustment1)->shouldBeCalled(); $unit2->addAdjustment($promotionAdjustment2)->shouldBeCalled(); $this->execute($order, ['percentage' => 0.2], $promotion); }
/** * {@inheritdoc} */ public function create(array $options = []) { $options = $this->optionsResolver->resolve($options); /** @var PromotionInterface $promotion */ $promotion = $this->promotionFactory->createNew(); $promotion->setCode($options['code']); $promotion->setName($options['name']); $promotion->setDescription($options['description']); $promotion->setCouponBased($options['coupon_based']); $promotion->setUsageLimit($options['usage_limit']); $promotion->setExclusive($options['exclusive']); $promotion->setPriority($options['priority']); if (isset($options['starts_at'])) { $promotion->setStartsAt(new \DateTime($options['starts_at'])); } if (isset($options['ends_at'])) { $promotion->setEndsAt(new \DateTime($options['ends_at'])); } foreach ($options['channels'] as $channel) { $promotion->addChannel($channel); } foreach ($options['rules'] as $rule) { /** @var PromotionRuleInterface $promotionRule */ $promotionRule = $this->promotionRuleExampleFactory->create($rule); $promotion->addRule($promotionRule); } foreach ($options['actions'] as $action) { /** @var PromotionActionInterface $promotionAction */ $promotionAction = $this->promotionActionExampleFactory->create($action); $promotion->addAction($promotionAction); } return $promotion; }
function it_creates_a_coupon_and_assigns_a_promotion_to_id(FactoryInterface $factory, PromotionRepositoryInterface $promotionRepository, PromotionInterface $promotion, CouponInterface $coupon) { $factory->createNew()->willReturn($coupon); $promotionRepository->find(13)->willReturn($promotion); $coupon->setPromotion($promotion)->shouldBeCalled(); $this->createForPromotion(13)->shouldReturn($coupon); }
/** * {@inheritdoc} */ public function createWithCustomer(CustomerInterface $customer) { /** @var AddressInterface $address*/ $address = $this->decoratedFactory->createNew(); $address->setCustomer($customer); return $address; }
/** * {@inheritdoc} */ public function createNew() { /** @var StaticContent $staticContent */ $staticContent = $this->decoratedFactory->createNew(); $staticContent->setParentDocument($this->documentManager->find(null, $this->staticContentParentPath)); return $staticContent; }
/** * {@inheritdoc} */ public function createNew() { $variant = $this->variantFactory->createNew(); $variant->setMaster(true); $product = $this->factory->createNew(); $product->setMasterVariant($variant); return $product; }