/** * @Given default currency is :currencyCode */ public function defaultCurrencyIs($currencyCode) { $currency = $this->createCurrency($currencyCode); $currency->setEnabled(true); $channel = $this->sharedStorage->get('channel'); $channel->setDefaultCurrency($currency); $this->saveCurrency($currency); }
/** * @Given default currency is :currencyCode */ public function defaultCurrencyIs($currencyCode) { $currency = $this->currencyFactory->createNew(); $currency->setCode($currencyCode); $currency->setExchangeRate(1.0); $channel = $this->sharedStorage->get('channel'); $channel->setDefaultCurrency($currency); $this->currencyRepository->add($currency); }
/** * @Given /^the store has a product "([^"]+)"$/ * @Given /^the store has a product "([^"]+)" priced at ("[^"]+")$/ */ public function storeHasAProductPricedAt($productName, $price = 0) { $product = $this->productFactory->createNew(); $product->setName($productName); $product->setPrice($price); $product->setDescription('Awesome ' . $productName); $channel = $this->sharedStorage->get('channel'); $product->addChannel($channel); $this->productRepository->add($product); $this->sharedStorage->set('product', $product); }
/** * @Given the store allows paying :paymentMethodName * @Given the store allows paying with :paymentMethodName */ public function storeAllowsPaying($paymentMethodName) { $paymentMethod = $this->paymentMethodFactory->createNew(); $paymentMethod->setCode('PM_' . $paymentMethodName); $paymentMethod->setName(ucfirst($paymentMethodName)); $paymentMethod->setGateway($this->paymentMethodNameToGatewayConverter->convert($paymentMethodName)); $paymentMethod->setDescription('Payment method'); $channel = $this->sharedStorage->get('channel'); $channel->addPaymentMethod($paymentMethod); $this->paymentMethodRepository->add($paymentMethod); }
function it_throws_runtime_exception_if_cannot_find_last_order_for_given_customer(SharedStorageInterface $sharedStorage, OrderRepositoryInterface $orderRepository, UserInterface $user, CustomerInterface $customer) { $sharedStorage->get('user')->willReturn($user); $user->getCustomer()->willReturn($customer); $orderRepository->findByCustomer($customer)->willReturn([]); $this->shouldThrow(\RuntimeException::class)->during('iTryToPayAgain'); }
function it_throws_exception_when_a_coupon_is_found_but_it_should_not_exist(SharedStorageInterface $sharedStorage, RepositoryInterface $couponRepository, CouponInterface $coupon) { $coupon->getId()->willReturn(5); $sharedStorage->get('coupon_id')->willReturn(5); $couponRepository->find(5)->willReturn($coupon); $this->shouldThrow(NotEqualException::class)->during('couponShouldNotExistInTheRegistry', [5]); }
/** * @Given my default shipping address is :country */ public function myDefaultShippingAddressIs($country) { $user = $this->sharedStorage->get('user'); $customer = $user->getCustomer(); $customer->setShippingAddress($this->createAddress($customer->getFirstName(), $customer->getLastName(), $country)); $this->userManager->flush(); }
function it_throws_an_exception_if_a_product_exists_when_it_should_not(SharedStorageInterface $sharedStorage, IndexPageInterface $adminProductIndexPage, ProductInterface $product) { $sharedStorage->get('product')->willReturn($product); $adminProductIndexPage->open()->shouldBeCalled(); $adminProductIndexPage->isThereProduct($product)->willReturn(true); $this->shouldThrow(NotEqualException::class)->during('productShouldNotExist', [$product]); }
/** * @Then I should see the thank you page */ public function iShouldSeeTheThankYouPage() { /** @var UserInterface $user */ $user = $this->sharedStorage->get('user'); $customer = $user->getCustomer(); expect($this->checkoutThankYouPage->hasThankYouMessageFor($customer->getFullName()))->toBe(true); }
/** * @param CustomerInterface $customer * @param string $number * @param ChannelInterface|null $channel * @param CurrencyInterface|null $currency * * @return OrderInterface */ private function createOrder(CustomerInterface $customer, $number, ChannelInterface $channel = null, CurrencyInterface $currency = null) { $order = $this->orderFactory->createNew(); $order->setCustomer($customer); $order->setNumber($number); $order->setChannel(null !== $channel ? $channel : $this->sharedStorage->get('channel')); $order->setCurrency(null !== $currency ? $currency : $this->sharedStorage->get('currency')); return $order; }
function it_checks_if_account_was_deleted(SharedStorageInterface $sharedStorage, UserInterface $user, CustomerInterface $customer, CustomerShowPage $customerShowPage) { $sharedStorage->get('deleted_user')->willReturn($user); $user->getCustomer()->willReturn($customer); $customer->getId()->willReturn(1); $customerShowPage->open(['id' => 1])->shouldBeCalled(); $customerShowPage->isRegistered()->willReturn(false); $this->accountShouldBeDeleted(); }
function it_checks_if_customer_still_exists(ShowPageInterface $customerShowPage, SharedStorageInterface $sharedStorage, CustomerInterface $customer, UserInterface $user) { $sharedStorage->get('deleted_user')->shouldBeCalled()->willReturn($user); $user->getCustomer()->willReturn($customer); $customer->getId()->willReturn(1); $customerShowPage->open(['id' => 1])->shouldBeCalled(); $customerShowPage->isRegistered()->willReturn(false); $this->customerShouldStillExist(); }
/** * @return OrderInterface * * @throws \RuntimeException */ private function getLastOrder() { $customer = $this->sharedStorage->get('user')->getCustomer(); $orders = $this->orderRepository->findByCustomer($customer); $lastOrder = end($orders); if (false === $lastOrder) { throw new \RuntimeException(sprintf('There is no last order for %s', $customer->getFullName())); } return $lastOrder; }
function it_creates_fixed_discount_promotion_for_cart_with_specified_quantity(ActionFactoryInterface $actionFactory, ActionInterface $action, ObjectManager $objectManager, PromotionInterface $promotion, RuleFactoryInterface $ruleFactory, RuleInterface $rule, SharedStorageInterface $sharedStorage) { $sharedStorage->get('promotion')->willReturn($promotion); $actionFactory->createFixedDiscount(1000)->willReturn($action); $promotion->addAction($action)->shouldBeCalled(); $ruleFactory->createCartQuantity(5)->willReturn($rule); $promotion->addRule($rule)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $this->itGivesFixedDiscountToEveryOrderWithQuantityAtLeast($promotion, 1000, '5'); }
/** * @Given /^(this product) is available in "([^"]+)" size priced at ("[^"]+")$/ */ public function thisProductIsAvailableInSize(ProductInterface $product, $optionValueName, $price) { /** @var ProductVariantInterface $variant */ $variant = $this->productVariantFactory->createNew(); $optionValue = $this->sharedStorage->get(sprintf('%s_option_value', $optionValueName)); $variant->addOption($optionValue); $variant->setPrice($price); $variant->setCode(sprintf("%s_%s", $product->getCode(), $optionValueName)); $product->addVariant($variant); $this->objectManager->flush(); }
function it_creates_a_review_for_a_given_product(SharedStorageInterface $sharedStorage, FactoryInterface $reviewFactory, RepositoryInterface $productReviewRepository, ProductInterface $product, ReviewInterface $review) { $sharedStorage->get('product')->willReturn($product); $reviewFactory->createNew()->willReturn($review); $review->setTitle('title')->shouldBeCalled(); $review->setRating(5)->shouldBeCalled(); $review->setReviewSubject($product)->shouldBeCalled(); $product->addReview($review)->shouldBeCalled(); $productReviewRepository->add($review); $this->productHasAReview($product); }
/** * @param ProductVariantInterface $productVariant * @param int $price * * @return OrderInterface */ private function addSingleProductVariantToOrder(ProductVariantInterface $productVariant, $price) { $order = $this->sharedStorage->get('order'); /** @var OrderItemInterface $item */ $item = $this->orderItemFactory->createNew(); $item->setVariant($productVariant); $item->setUnitPrice($price); $this->itemQuantityModifier->modify($item, 1); $order->addItem($item); $this->orderRecalculator->recalculate($order); return $order; }
/** * @Given the store has promotion :promotionName with coupon :couponCode */ public function thereIsPromotionWithCoupon($promotionName, $couponCode) { /** @var CouponInterface $coupon */ $coupon = $this->couponFactory->createNew(); $coupon->setCode($couponCode); $promotion = $this->testPromotionFactory->createForChannel($promotionName, $this->sharedStorage->get('channel')); $promotion->addCoupon($coupon); $promotion->setCouponBased(true); $this->promotionRepository->add($promotion); $this->sharedStorage->set('promotion', $promotion); $this->sharedStorage->set('coupon', $coupon); }
/** * @Given the customer bought single :product */ public function theCustomerBoughtSingle(ProductInterface $product) { /** @var OrderInterface $order */ $order = $this->sharedStorage->get('order'); /** @var OrderItemInterface $item */ $item = $this->orderItemFactory->createNew(); $item->setVariant($product->getMasterVariant()); $item->setUnitPrice($product->getPrice()); $this->itemQuantityModifier->modify($item, 1); $order->addItem($item); $this->objectManager->flush(); }
function it_adds_single_item_by_customer(FactoryInterface $orderItemFactory, OrderInterface $order, OrderItemInterface $item, OrderItemQuantityModifierInterface $itemQuantityModifier, ProductInterface $product, SharedStorageInterface $sharedStorage, ProductVariantInterface $variant, ObjectManager $objectManager) { $sharedStorage->get('order')->willReturn($order); $orderItemFactory->createNew()->willReturn($item); $product->getMasterVariant()->willReturn($variant); $product->getPrice()->willReturn(1234); $itemQuantityModifier->modify($item, 1)->shouldBeCalled(); $item->setVariant($variant)->shouldBeCalled(); $item->setUnitPrice(1234)->shouldBeCalled(); $order->addItem($item)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $this->theCustomerBoughtSingle($product); }
/** * @param string $name * @param string $locale * @param array $configuration * @param string $calculator * @param ZoneInterface|null $zone */ private function createShippingMethod($name, $zone = null, $locale = 'en', $configuration = ['amount' => 0], $calculator = DefaultCalculators::FLAT_RATE) { if (null === $zone) { $zone = $this->sharedStorage->get('zone'); } $shippingMethod = $this->shippingMethodFactory->createNew(); $shippingMethod->setCode($this->generateCodeFromNameAndZone($name, $zone->getCode())); $shippingMethod->setName($name); $shippingMethod->setCurrentLocale($locale); $shippingMethod->setConfiguration($configuration); $shippingMethod->setCalculator($calculator); $shippingMethod->setZone($zone); $this->shippingMethodRepository->add($shippingMethod); }
/** * @param string $name * @param string|null $code * @param ZoneInterface|null $zone * @param string $locale * @param array $configuration * @param string $calculator * @param bool $enabled * @param bool $addForCurrentChannel */ private function createShippingMethod($name, $code = null, ZoneInterface $zone = null, $locale = 'en', $configuration = ['amount' => 0], $calculator = DefaultCalculators::FLAT_RATE, $enabled = true, $addForCurrentChannel = true) { if (null === $zone) { $zone = $this->sharedStorage->get('zone'); } if (null === $code) { $code = $this->generateCodeFromNameAndZone($name, $zone->getCode()); } /** @var ShippingMethodInterface $shippingMethod */ $shippingMethod = $this->shippingMethodFactory->createNew(); $shippingMethod->setCode($code); $shippingMethod->setName($name); $shippingMethod->setCurrentLocale($locale); $shippingMethod->setConfiguration($configuration); $shippingMethod->setCalculator($calculator); $shippingMethod->setZone($zone); $shippingMethod->setEnabled($enabled); if ($addForCurrentChannel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); $channel->addShippingMethod($shippingMethod); } $this->shippingMethodRepository->add($shippingMethod); $this->sharedStorage->set('shipping_method', $shippingMethod); }
/** * @Then /^this variant should not exist in the product catalog$/ */ public function productVariantShouldNotExistInTheProductCatalog() { $productVariantId = $this->sharedStorage->get('product_variant_id'); $productVariant = $this->productVariantRepository->find($productVariantId); expect($productVariant)->toBe(null); }
/** * @Given his account was deleted */ public function hisAccountWasDeleted() { $user = $this->sharedStorage->get('user'); $this->userRepository->remove($user); }
/** * @param string $element * @param string $message */ private function assertValidationMessage($element, $message) { $product = $this->sharedStorage->has('product') ? $this->sharedStorage->get('product') : null; $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createSimpleProductPage, $this->createConfigurableProductPage, $this->updateSimpleProductPage, $this->updateConfigurableProductPage], $product); Assert::true($currentPage->checkValidationMessageFor($element, $message), sprintf('Product %s should be required.', $element)); }
function it_transforms_this_that_and_the_should_no_longer_with_resource_name_to_current_id_set_for_that_resource(SharedStorageInterface $sharedStorage) { $sharedStorage->get('customer_id')->willReturn(5); $this->getResourceId('customer')->shouldReturn(5); }
/** * @Then the user account should be deleted */ public function accountShouldBeDeleted() { $deletedUser = $this->sharedStorage->get('deleted_user'); $this->customerShowPage->open(['id' => $deletedUser->getCustomer()->getId()]); expect($this->customerShowPage->isRegistered())->toBe(false); }
/** * @Transform /^(?:this|that|the) ([^"]+)$/ */ public function getResource($resource) { return $this->sharedStorage->get($resource); }
/** * @Transform /^(?:this|that|the) ([^"]+)$/ */ public function getResource($resource) { return $this->sharedStorage->get(StringInflector::nameToCode($resource)); }
/** * @Then I should be notified that it is in use and cannot be deleted */ public function iShouldBeNotifiedOfFailure() { expect($this->sharedStorage->get('last_exception'))->toBeAnInstanceOf(ForeignKeyConstraintViolationException::class); }