1 | <?php |
||
13 | class CheckoutServiceTest extends \PHPUnit_Framework_TestCase |
||
14 | { |
||
15 | /** |
||
16 | * @var Client|\PHPUnit_Framework_MockObject_MockObject |
||
17 | */ |
||
18 | private $client; |
||
19 | |||
20 | /** |
||
21 | * @var Credentials |
||
22 | */ |
||
23 | private $credentials; |
||
24 | |||
25 | protected function setUp() |
||
26 | { |
||
27 | $environment = $this->getMockForAbstractClass(Environment::class); |
||
28 | |||
29 | $environment->expects($this->any()) |
||
30 | ->method('getHost') |
||
31 | ->willReturn('test.com'); |
||
32 | |||
33 | $environment->expects($this->any()) |
||
34 | ->method('getWsHost') |
||
35 | ->willReturn('ws.test.com'); |
||
36 | |||
37 | $this->credentials = new Credentials('[email protected]', 'test', $environment); |
||
38 | $this->client = $this->createMock(Client::class); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @test |
||
43 | */ |
||
44 | public function checkoutShouldDoAPostRequestReturningTheRedirection() |
||
45 | { |
||
46 | $checkout = new Checkout(); |
||
47 | |||
48 | $wsUri = 'https://ws.test.com/v2/checkout?email=test%40test.com&token=test'; |
||
49 | $request = simplexml_load_string( |
||
50 | '<?xml version="1.0" encoding="UTF-8"?>' |
||
51 | . '<checkout><currency>BRL</currency></checkout>' |
||
52 | ); |
||
53 | |||
54 | $response = simplexml_load_string( |
||
55 | '<?xml version="1.0" encoding="UTF-8"?>' |
||
56 | . '<checkout><code>123</code><date>2010-12-02T10:11:28.000-02:00</date></checkout>' |
||
57 | ); |
||
58 | |||
59 | $this->client->expects($this->once()) |
||
60 | ->method('post') |
||
61 | ->with($wsUri, $request) |
||
62 | ->willReturn($response); |
||
63 | |||
64 | $service = new CheckoutService($this->credentials, $this->client); |
||
65 | $redirection = $service->checkout($checkout); |
||
66 | |||
67 | $redirectUri = 'https://test.com/v2/checkout/payment.html'; |
||
68 | |||
69 | $this->assertInstanceOf(Redirection::class, $redirection); |
||
70 | $this->assertAttributeEquals($redirectUri, 'uri', $redirection); |
||
71 | $this->assertAttributeEquals('123', 'code', $redirection); |
||
72 | $this->assertAttributeEquals(new DateTime('2010-12-02T10:11:28.000-02:00'), 'date', $redirection); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @test |
||
77 | */ |
||
78 | public function createCheckoutBuilderShouldReturnANewBuilderInstance() |
||
79 | { |
||
80 | $service = new CheckoutService($this->credentials, $this->client); |
||
81 | |||
82 | $this->assertInstanceOf(CheckoutBuilder::class, $service->createCheckoutBuilder()); |
||
83 | } |
||
84 | } |
||
85 |