/**
  * @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);
 }
 /**
  * @test
  */
 public function checkoutShouldDoAPostRequestReturningTheRedirection()
 {
     $checkout = $this->getMock('PHPSC\\PagSeguro\\Requests\\Checkout\\Checkout', [], [], '', false);
     $wsUri = 'https://ws.test.com/v2/checkout?email=test%40test.com&token=test';
     $request = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><checkout />');
     $response = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?>' . '<checkout><code>123</code><date>2010-12-02T10:11:28.000-02:00</date></checkout>');
     $this->serializer->expects($this->once())->method('serialize')->with($checkout)->willReturn($request);
     $this->client->expects($this->once())->method('post')->with($wsUri, $request)->willReturn($response);
     $service = new CheckoutService($this->credentials, $this->client, $this->serializer);
     $redirection = $service->checkout($checkout);
     $redirectUri = 'https://test.com/v2/checkout/payment.html';
     $this->assertInstanceOf('PHPSC\\PagSeguro\\Requests\\Redirection', $redirection);
     $this->assertAttributeEquals($redirectUri, 'uri', $redirection);
     $this->assertAttributeEquals('123', 'code', $redirection);
     $this->assertAttributeEquals(new DateTime('2010-12-02T10:11:28.000-02:00'), 'date', $redirection);
 }
 /**
  * {@inheritdoc}
  */
 public function checkout(Checkout $checkout)
 {
     $response = $this->post(static::ENDPOINT, $this->serializer->serialize($checkout));
     return $this->getRedirection($response);
 }