/**
  * Test form creation
  */
 public function testFormCreation()
 {
     $amount = 100;
     $formData = array('Ds_Merchant_Amount' => $amount, 'Ds_Merchant_MerchantSignature' => 'CB43B12351A9826D9640CC285CBDFD8CA6A5994C', 'Ds_Merchant_MerchantCode' => $this::merchantCode, 'Ds_Merchant_Currency' => '978', 'Ds_Merchant_Terminal' => $this::terminal, 'Ds_Merchant_Order' => '342', 'Ds_Merchant_MerchantURL' => '/payment/redsys/result', 'Ds_Merchant_UrlOK' => '/payment/redsys/checkout/ok', 'Ds_Merchant_UrlKO' => '/payment/redsys/checkout/ko', 'Ds_Merchant_TransactionType' => $this::transactionType, 'Ds_Merchant_ProductDescription' => $this::prodDesc, 'Ds_Merchant_Titular' => $this::titular, 'Ds_Merchant_MerchantName' => $this::name);
     $this->paymentBridge->expects($this->once())->method('getExtraData')->will($this->returnValue(array('terminal' => $this::terminal, 'transaction_type' => $this::transactionType, 'product_description' => $this::prodDesc, 'merchant_titular' => $this::titular, 'merchant_name' => $this::name)));
     $this->paymentBridge->expects($this->once())->method('getAmount')->will($this->returnValue($amount));
     $this->paymentBridge->expects($this->once())->method('getOrderNumber')->will($this->returnValue('342'));
     $this->paymentBridge->expects($this->once())->method('getCurrency')->will($this->returnValue('EUR'));
     $this->urlFactory->expects($this->once())->method('getReturnUrlOkForOrderId')->will($this->returnValue('/payment/redsys/checkout/ok'));
     $this->urlFactory->expects($this->once())->method('getReturnUrlKoForOrderId')->will($this->returnValue('/payment/redsys/checkout/ko'));
     $this->urlFactory->expects($this->once())->method('getReturnRedsysUrl')->will($this->returnValue('/payment/redsys/result'));
     $formView = $this->redsysFormTypeWrapper->buildForm();
     $children = $formView->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
         $message = $formData[$key] . ':::' . $children[$key]->vars['value'];
         $this->assertEquals($formData[$key], $children[$key]->vars['value'], $message);
     }
 }
 /**
  * Testing payment Success
  */
 public function testPaymentSuccess()
 {
     $this->paymillMethod->expects($this->once())->method('getApiToken')->will($this->returnValue(self::API_TOKEN));
     $this->paymentBridge->expects($this->once())->method('getOrder')->will($this->returnValue(1));
     $this->paymillMethod->expects($this->any())->method('setTransactionId')->with($this->equalTo('123'))->will($this->returnValue($this->paymillMethod));
     $this->paymillMethod->expects($this->any())->method('setTransactionStatus')->with($this->equalTo('closed'))->will($this->returnValue($this->paymillMethod));
     $this->paymentBridge->expects($this->once())->method('getCurrency')->will($this->returnValue(self::CURRENCY));
     $this->paymentBridge->expects($this->once())->method('getAmount')->will($this->returnValue(self::ORDER_AMOUNT));
     $this->paymentBridge->expects($this->once())->method('getExtraData')->will($this->returnValue(array('order_description' => self::ORDER_DESCRIPTION)));
     $this->paymillResponseTransaction->expects($this->once())->method('getStatus')->will($this->returnValue('closed'));
     $this->paymillResponseTransaction->expects($this->once())->method('getId')->will($this->returnValue(123));
     $this->paymillTransactionWrapper->expects($this->once())->method('create')->with($this->equalTo(self::ORDER_AMOUNT), $this->equalTo(self::CURRENCY), $this->equalTo(self::API_TOKEN), $this->equalTo(self::ORDER_DESCRIPTION))->will($this->returnValue($this->paymillResponseTransaction));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderLoad')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderCreated')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymentEventDispatcher->expects($this->any())->method('notifyPaymentOrderFail');
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderSuccess')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->paymillMethod));
     $this->paymillManager->processPayment($this->paymillMethod, self::ORDER_AMOUNT);
 }
 /**
  * Testing payment error
  *
  */
 public function testPaymentSuccess()
 {
     $this->redsysApiMethod->expects($this->once())->method('getCreditCartNumber')->will($this->returnValue(self::CART_NUMBER));
     $this->redsysApiMethod->expects($this->once())->method('getCreditCartExpirationMonth')->will($this->returnValue(self::CART_EXPIRE_MONTH));
     $this->redsysApiMethod->expects($this->once())->method('getCreditCartExpirationYear')->will($this->returnValue(self::CART_EXPIRE_YEAR));
     $this->paymentBridge->expects($this->once())->method('getOrder')->will($this->returnValue(1));
     $this->redsysApiMethod->expects($this->any())->method('setTransactionId')->with($this->equalTo('123'))->will($this->returnValue($this->redsysApiMethod));
     $this->redsysApiMethod->expects($this->any())->method('setTransactionStatus')->with($this->equalTo('paid'))->will($this->returnValue($this->redsysApiMethod));
     $this->paymentBridge->expects($this->once())->method('getCurrency')->will($this->returnValue(self::CURRENCY));
     $this->paymentBridge->expects($this->once())->method('getAmount')->will($this->returnValue(self::CART_AMOUNT));
     $cart = array('number' => self::CART_NUMBER, 'exp_month' => self::CART_EXPIRE_MONTH, 'exp_year' => self::CART_EXPIRE_YEAR);
     $chargeParams = array('card' => $cart, 'amount' => self::CART_AMOUNT, 'currency' => strtolower(self::CURRENCY));
     $this->redsysApiTransactionWrapper->expects($this->once())->method('create')->with($chargeParams)->will($this->returnValue(array('paid' => '1', 'id' => '123')));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderLoad')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->redsysApiMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderCreated')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->redsysApiMethod));
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderDone')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->redsysApiMethod));
     $this->paymentEventDispatcher->expects($this->any())->method('notifyPaymentOrderFail');
     $this->paymentEventDispatcher->expects($this->once())->method('notifyPaymentOrderSuccess')->with($this->equalTo($this->paymentBridge), $this->equalTo($this->redsysApiMethod));
     $this->redsysApiManager->processPayment($this->redsysApiMethod, self::CART_AMOUNT);
 }