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