/** * Test create and save * * @covers createAndSaveCartCoupon */ public function testCreateAndSaveCartCoupon() { $cart = $this->prophesize('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface'); $coupon = $this->prophesize('Elcodi\\Component\\Coupon\\Entity\\Interfaces\\CouponInterface'); $cartCoupon = $this->prophesize('Elcodi\\Component\\CartCoupon\\Entity\\Interfaces\\CartCouponInterface')->reveal(); $this->cartCouponDirector->create(Argument::any())->willReturn($cartCoupon)->shouldBeCalled(); $this->cartCouponDirector->save($cartCoupon)->shouldBeCalled(); $cartCouponManager = $this->createCartCouponManagerInstance(); $cartCouponManager->createAndSaveCartCoupon($cart->reveal(), $coupon->reveal()); }
/** * Remove a comment * * @param CommentInterface $comment Comment * * @return $this Self object */ public function removeComment(CommentInterface $comment) { $this->commentEventDispatcher->dispatchCommentPreRemoveEvent($comment); $this->commentDirector->save($comment); $this->commentEventDispatcher->dispatchCommentOnRemoveEvent($comment); return $this; }
/** * Vote action * * @param CommentInterface $comment Comment * @param string $authorToken Author token * @param boolean $type Vote type * * @return VoteInterface Vote */ public function vote(CommentInterface $comment, $authorToken, $type) { /** * @var VoteInterface $vote */ $vote = $this->commentVoteObjectDirector->findOneBy(['authorToken' => $authorToken, 'comment' => $comment]); $edited = true; if (!$vote instanceof VoteInterface) { $vote = $this->commentVoteObjectDirector->create()->setAuthorToken($authorToken)->setComment($comment); $edited = false; } $vote->setType($type); $this->commentVoteObjectDirector->save($vote); $this->commentEventDispatcher->dispatchCommentOnVotedEvent($comment, $vote, $edited); return $vote; }
/** * Test that modifying a new root category the parent category should be * null. */ public function testEditRootCategoryIsSavedWithoutParent() { /** * @var $rootCategory CategoryInterface */ $rootCategory = $this->categoryDirector->findOneBy(['slug' => 'root-category']); /** * @var $anotherCategory CategoryInterface */ $anotherCategory = $this->categoryDirector->findOneBy(['slug' => 'category']); $rootCategory->setParent($anotherCategory); $this->categoryDirector->save($rootCategory); /** * @var $category CategoryInterface */ $category = $this->categoryDirector->findOneBy(['slug' => 'root-category']); $this->assertNull($category->getParent(), 'The parent for a root category should always be null'); }
/** * Create a new user from a response * * @param UserResponseInterface $response * * @return UserInterface */ protected function createUser(UserResponseInterface $response) { /** * @var CustomerInterface $customer */ $customer = $this->customerDirector->create(); $customer->setEmail($response->getEmail())->setFirstname($response->getRealName()); $this->customerDirector->save($customer); $this->userEventDispatcher->dispatchOnCustomerRegisteredEvent($customer); return $customer; }
/** * Create a cart coupon given a cart and a coupon. * * @param CartInterface $cart Cart * @param CouponInterface $coupon Coupon * * @return CartCouponInterface Cart Coupon created */ public function createAndSaveCartCoupon(CartInterface $cart, CouponInterface $coupon) { /** * We create a new instance of CartCoupon. * We also persist and flush relation. */ $cartCoupon = $this->cartCouponDirector->create(); $cartCoupon->setCart($cart); $cartCoupon->setCoupon($coupon); $this->cartCouponDirector->save($cartCoupon); return $cartCoupon; }
/** * Populates the exchange rates. * * @return $this Self object */ public function populate() { $currenciesCodes = []; $currencies = $this->currencyRepository->findAll(); /** * Create an array of all active currency codes. * * @var CurrencyInterface $currency */ foreach ($currencies as $currency) { if ($currency->getIso() != $this->defaultCurrency) { $currenciesCodes[] = $currency->getIso(); } } /** * Get rates for all of the enabled and active currencies. */ $rates = $this->currencyExchangeRatesAdapter->getExchangeRates($this->defaultCurrency, $currenciesCodes); /** * @var CurrencyInterface $sourceCurrency */ $sourceCurrency = $this->currencyRepository->findOneBy(['iso' => $this->defaultCurrency]); /** * [ * "EUR" => "1,378278", * "YEN" => "0,784937", * ]. */ foreach ($rates as $code => $rate) { /** * @var CurrencyInterface $targetCurrency */ $targetCurrency = $this->currencyRepository->findOneBy(['iso' => $code]); if (!$targetCurrency instanceof CurrencyInterface) { continue; } /** * check if this is a new exchange rate, or if we have to * create a new one. */ $exchangeRate = $this->currencyExchangeRateObjectDirector->findOneBy(['sourceCurrency' => $sourceCurrency, 'targetCurrency' => $targetCurrency]); if (!$exchangeRate instanceof CurrencyExchangeRateInterface) { $exchangeRate = $this->currencyExchangeRateObjectDirector->create(); } $exchangeRate->setExchangeRate($rate)->setSourceCurrency($sourceCurrency)->setTargetCurrency($targetCurrency); $this->currencyExchangeRateObjectDirector->save($exchangeRate); } return $this; }
/** * Test that the principal category is assigned as category when a product * is saved only with principal category. */ public function testProductIsSavedOnlyWithPrincipalCategory() { $category = $this->categoryRepository->findOneBy(['slug' => 'category']); /** * @var ProductInterface $product */ $product = $this->getNewProduct(); $product->setPrincipalCategory($category); $product->setSlug('new-product-2'); $product->setName('New product 2'); $this->productDirector->save($product); $product = $this->productDirector->findOneBy(['slug' => 'new-product-2']); $this->assertEquals(1, $product->getCategories()->count(), 'The product is expected to have one category'); $this->assertEquals($category, $product->getCategories()->first(), 'The returned category should be the principal category'); }