Example #1
0
 /**
  * @covers \Elcodi\Component\Currency\Entity\Money::__construct
  * @covers \Elcodi\Component\Currency\Entity\Money::newWrappedMoneyFromMoney
  */
 public function testInitialize()
 {
     $currencyMock = new Currency();
     $currencyMock->setIso('USD');
     $twoHundredDollars = Money::create(200, $currencyMock);
     $this->assertInstanceOf('\\Elcodi\\Component\\Currency\\Entity\\Money', $twoHundredDollars);
 }
Example #2
0
 /**
  * Return the fields to test in entities.
  *
  * [
  *      [[
  *          "type" => $this::GETTER_SETTER,
  *          "getter" => "getValue",
  *          "setter" => "setValue",
  *          "value" => "Elcodi\Component\...\Interfaces\AnInterface"
  *          "nullable" => true
  *      ]],
  *      [[
  *          "type" => $this::ADDER_REMOVER|$this::ADDER_REMOVER,
  *          "getter" => "getValue",
  *          "setter" => "setValue",
  *          "adder" => "addValue",
  *          "removed" => "removeValue",
  *          "bag" => "collection", // can be array
  *          "value" => "Elcodi\Component\...\Interfaces\AnInterface"
  *      ]]
  * ]
  *
  * @return array Fields
  */
 public function getTestableFields()
 {
     $currency = new Currency();
     $currency->setIso('EUR');
     $currency->setSymbol('€');
     return [[['type' => $this::GETTER_SETTER, 'getter' => 'getCode', 'setter' => 'setCode', 'value' => 'discount', 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getName', 'setter' => 'setName', 'value' => 'Discount', 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getEnforcement', 'setter' => 'setEnforcement', 'value' => ElcodiCouponTypes::ENFORCEMENT_AUTOMATIC, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getPrice', 'setter' => 'setPrice', 'value' => Money::create(1000, $currency), 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getDiscount', 'setter' => 'setDiscount', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getAbsolutePrice', 'setter' => 'setAbsolutePrice', 'value' => Money::create(1000, $currency), 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getValue', 'setter' => 'setValue', 'value' => 'value', 'nullable' => true]], [['type' => $this::GETTER_SETTER, 'getter' => 'getCount', 'setter' => 'setCount', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getUsed', 'setter' => 'setUsed', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getPriority', 'setter' => 'setPriority', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getMinimumPurchase', 'setter' => 'setMinimumPurchase', 'value' => Money::create(1000, $currency), 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getStackable', 'setter' => 'setStackable', 'value' => true, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getRule', 'setter' => 'setRule', 'value' => new Rule(), 'nullable' => true]]];
 }
 /**
  * Set up.
  */
 public function setUp()
 {
     /**
      * @var CartEventDispatcher     $cartEventDispatcher
      * @var CartLineEventDispatcher $cartLineEventDispatcher
      * @var CartFactory             $cartFactory
      * @var CartLineFactory         $cartLineFactory
      * @var CartWrapper             $cartWrapper
      */
     $emptyMoneyWrapper = $this->getMock('Elcodi\\Component\\Currency\\Wrapper\\EmptyMoneyWrapper', [], [], '', false);
     $currency = new Currency();
     $currency->setIso('EUR');
     $emptyMoneyWrapper->expects($this->any())->method('get')->willReturn(Money::create(0, $currency));
     $cartEventDispatcher = $this->getMock('Elcodi\\Component\\Cart\\EventDispatcher\\CartEventDispatcher', [], [], '', false);
     $cartLineEventDispatcher = $this->getMock('Elcodi\\Component\\Cart\\EventDispatcher\\CartLineEventDispatcher', [], [], '', false);
     $cartFactory = $this->getMock('Elcodi\\Component\\Cart\\Factory\\CartFactory', ['create'], [$emptyMoneyWrapper]);
     $cartLineFactory = $this->getMock('Elcodi\\Component\\Cart\\Factory\\CartLineFactory', ['create'], [$emptyMoneyWrapper]);
     $this->cartManager = new CartManager($cartEventDispatcher, $cartLineEventDispatcher, $cartFactory, $cartLineFactory);
     $this->cartFactory = $cartFactory;
     $this->cartLineFactory = $cartLineFactory;
 }
Example #4
0
 /**
  * Testing that when I add a product with id 1 and a variant with the same
  * id (1), new variant is added into the cart, instead of incrementing first
  * mentioned product.
  */
 public function testAddProductAndVariantSameId()
 {
     /**
      * @var CartEventDispatcher     $cartEventDispatcher
      * @var CartLineEventDispatcher $cartLineEventDispatcher
      * @var CartFactory             $cartFactory
      * @var CartLineFactory         $cartLineFactory
      * @var CartWrapper             $cartWrapper
      */
     $emptyMoneyWrapper = $this->getMock('Elcodi\\Component\\Currency\\Wrapper\\EmptyMoneyWrapper', [], [], '', false);
     $currency = new Currency();
     $currency->setIso('EUR');
     $emptyMoneyWrapper->expects($this->any())->method('get')->willReturn(Money::create(0, $currency));
     $cartEventDispatcher = $this->getMock('Elcodi\\Component\\Cart\\EventDispatcher\\CartEventDispatcher', [], [], '', false);
     $cartLineEventDispatcher = $this->getMock('Elcodi\\Component\\Cart\\EventDispatcher\\CartLineEventDispatcher', [], [], '', false);
     $cartFactory = $this->getMock('Elcodi\\Component\\Cart\\Factory\\CartFactory', ['create'], [$emptyMoneyWrapper]);
     $cartLineFactory = $this->getMock('Elcodi\\Component\\Cart\\Factory\\CartLineFactory', ['create'], [$emptyMoneyWrapper]);
     $cartLineFactory->expects($this->any())->method('create')->willReturn(new CartLine());
     $cartManager = $this->getMockBuilder('Elcodi\\Component\\Cart\\Services\\CartManager')->setMethods(['increaseCartLineQuantity'])->setConstructorArgs([$cartEventDispatcher, $cartLineEventDispatcher, $cartFactory, $cartLineFactory])->getMock();
     $cart = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface');
     $cartLine = $this->getMock('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartLineInterface');
     $product = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface');
     $variant = $this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\VariantInterface');
     $product->expects($this->any())->method('getId')->willReturn(1);
     $variant->expects($this->any())->method('getId')->willReturn(1);
     $variant->expects($this->any())->method('getProduct')->willReturn($this->getMock('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface'));
     $cartLine->expects($this->any())->method('getPurchasable')->willReturn($product);
     $cart->expects($this->any())->method('getCartLines')->willReturn(new ArrayCollection([$cartLine]));
     $cartManager->expects($this->never())->method('increaseCartLineQuantity');
     $cartManager->addPurchasable($cart, $variant, 1);
 }
 /**
  * Creates a currency.
  *
  * @param string $iso The currency ISO.
  *
  * @return CurrencyInterface
  */
 protected function createCurrency($iso)
 {
     $currency = new Currency();
     $currency->setIso($iso);
     return $currency;
 }
 /**
  * Get currency
  *
  * @return Currency Currency
  */
 private function getCurrency()
 {
     $currency = new Currency();
     $currency->setIso('EUR')->setSymbol("€")->getName("Euro");
     return $currency;
 }