/**
  * @test
  */
 public function testSerializeShouldReturnXMLFull()
 {
     $items = new Items();
     $items->add(new Item(77, 'Produto 01', 2.5, 4, 20, 300));
     $items->add(new Item(88, 'Produto 02', 342.51, 3, 134.98, 1000));
     $shippingAddress = new Address('CE', 'Ortega do Norte', '40610-912', 'Ipe', 'R. Regina Salas', '3601', 'Bl.A');
     $shipping = new Shipping(1, $shippingAddress, 23.45);
     $order = new Order($items);
     $order->setReference('REF1234');
     $order->setExtraAmount(1.01);
     $order->setShipping($shipping);
     $customerAddress = new Address('AC', 'Sao Maite', '99500-079', 'Centro', 'Rua David Delgado', '55', 'Fundos');
     $customerPhone = new Phone('11', '99999999');
     $customer = new Customer('*****@*****.**', 'FooBar', $customerPhone, $customerAddress);
     $checkout = new Checkout($order);
     $checkout->setCustomer($customer);
     $checkout->setRedirectTo('http://localhost/return.php');
     $checkout->setMaxUses(5);
     $checkout->setMaxAge(60);
     $serializer = new CheckoutSerializer();
     $xml = $serializer->serialize($checkout);
     $this->assertInstanceOf(SimpleXMLElement::class, $xml);
     $expected = simplexml_load_file(__DIR__ . '/xml/checkoutFull.xml');
     $this->assertEquals($expected, $xml);
 }
示例#2
0
 /**
  * @param SimpleXMLElement $itemsNode
  * @return array
  */
 protected function createItems(SimpleXMLElement $itemsNode)
 {
     $items = new Items();
     foreach ($itemsNode->item as $item) {
         $items->add(new Item((string) $item->id, (string) $item->description, (double) $item->amount, (int) $item->quantity, isset($item->shippingCost) ? (double) $item->shippingCost : null, isset($item->weight) ? (int) $item->weight : null));
     }
     return $items;
 }
 public function testSerializeShouldXMLFull()
 {
     $items = new Items();
     $items->add(new Item(99, 'Produto 03', 1.77, 8, 12.9, 360));
     $items->add(new Item(97, 'Produto 04', 43.67, 3, 134.98, 1100));
     $charge = new Charge($items);
     $charge->setSubscriptionCode(4556788);
     $charge->setReference('abcdef');
     $serializer = new ChargeSerializer();
     $xml = $serializer->serialize($charge);
     $this->assertInstanceOf(SimpleXMLElement::class, $xml);
     $expected = simplexml_load_file(__DIR__ . '/xml/chargeFull.xml');
     $this->assertEquals($expected, $xml);
 }
示例#4
0
 public function testDecodeShouldDoReturningObjectTransaction()
 {
     $detailsDate = new DateTime('2011-02-10T16:13:41.000-03:00');
     $detailsLastEventDate = new DateTime('2011-02-10T19:15:11.000-03:00');
     $detailsAddress = new Address('AC', 'Sao Maite', '99500079', 'Centro', 'R Delgado', '55', 'Fundos');
     $customer = new Customer('*****@*****.**', 'FooBar', new Phone('11', '99999999'), $detailsAddress);
     $details = new Details('9E884542', 'REF1234', '6', $detailsDate, $detailsLastEventDate, $customer);
     $paymentMethod = new PaymentMethod(1, 101);
     $escrowEndDate = new DateTime('2011-03-10T08:00:00.000-03:00');
     $payment = new Payment($paymentMethod, 49900.0, 0.01, 0.04, 49900.03, 0.02, 1, $escrowEndDate);
     $shippingAddress = new Address('CE', 'Ortega', '40610912', 'Ipe', 'R. Regina', '36', 'Bl.A');
     $shipping = new Shipping(2, $shippingAddress, 23.45);
     $items = new Items();
     $items->add(new Item(77, 'Produto 01', 2.5, 4, 20, 300));
     $items->add(new Item(88, 'Produto 02', 342.51, 3, 134.98, 1000));
     $transaction = new Transaction($details, $payment, 2, $items, $shipping);
     $obj = simplexml_load_file(__DIR__ . '/xml/transactionFull.xml');
     $decoder = new Decoder();
     $this->assertEquals($transaction, $decoder->decode($obj));
 }