1 | <?php |
||
14 | class SubscriptionServiceTest extends \PHPUnit_Framework_TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var Credentials|\PHPUnit_Framework_MockObject_MockObject |
||
18 | */ |
||
19 | private $credentials; |
||
20 | |||
21 | /** |
||
22 | * @var Client|\PHPUnit_Framework_MockObject_MockObject |
||
23 | */ |
||
24 | private $client; |
||
25 | |||
26 | /** |
||
27 | * @var ChargeSerializer|\PHPUnit_Framework_MockObject_MockObject |
||
28 | */ |
||
29 | private $serializer; |
||
30 | |||
31 | protected function setUp() |
||
32 | { |
||
33 | $this->credentials = $this->createMock(Credentials::class); |
||
34 | $this->client = $this->createMock(Client::class); |
||
35 | $this->serializer = $this->createMock(ChargeSerializer::class); |
||
36 | } |
||
37 | |||
38 | public function testConstructShouldSettersDecoder() |
||
39 | { |
||
40 | $service = new SubscriptionService($this->credentials, $this->client, $this->serializer); |
||
41 | |||
42 | $this->assertInstanceOf(SubscriptionServiceInterface::class, $service); |
||
43 | $this->assertInstanceOf(Service::class, $service); |
||
44 | $this->assertAttributeSame($this->serializer, 'serializer', $service); |
||
45 | } |
||
46 | |||
47 | public function testCreateChargeBuilderShouldReturnObjectBuilder() |
||
48 | { |
||
49 | $service = new SubscriptionService($this->credentials, $this->client, $this->serializer); |
||
50 | |||
51 | $this->assertEquals(new ChargeBuilder('ABCDEF'), $service->createChargeBuilder('ABCDEF')); |
||
52 | } |
||
53 | |||
54 | public function testCancelShouldDoReturnCancellationResponse() |
||
55 | { |
||
56 | $wsUrl = 'https://ws.test.com/v2/transactions?token=zzzzz'; |
||
57 | $this->credentials |
||
58 | ->expects($this->once()) |
||
59 | ->method('getWsUrl') |
||
60 | ->with('/v2/pre-approvals/cancel/ABCDEF', []) |
||
61 | ->willReturn($wsUrl); |
||
62 | |||
63 | $response = '<?xml version="1.0" encoding="UTF-8"?><transaction>'; |
||
64 | $response .= '<status>6</status><date>2015-11-19T11:33:54.000-03:00</date>'; |
||
65 | $response .= '</transaction>'; |
||
66 | $xmlResponse = new SimpleXMLElement($response); |
||
67 | $this->client |
||
68 | ->expects($this->once()) |
||
69 | ->method('get') |
||
70 | ->with($wsUrl) |
||
71 | ->willReturn($xmlResponse); |
||
72 | |||
73 | $service = new SubscriptionService($this->credentials, $this->client, $this->serializer); |
||
74 | |||
75 | $expected = new CancellationResponse('6', new DateTime('2015-11-19T11:33:54.000-03:00')); |
||
76 | $this->assertEquals($expected, $service->cancel('ABCDEF')); |
||
77 | } |
||
78 | |||
79 | public function testChargeShouldDoReturnChargeResponse() |
||
80 | { |
||
81 | $charge = $this->createMock(Charge::class); |
||
82 | |||
83 | $request = '<?xml version="1.0" encoding="UTF-8"?><payment/>'; |
||
84 | $xmlRequest = new SimpleXMLElement($request); |
||
85 | $this->serializer |
||
86 | ->expects($this->once()) |
||
87 | ->method('serialize') |
||
88 | ->with($charge) |
||
89 | ->willReturn($xmlRequest); |
||
90 | |||
91 | $wsUrl = 'https://ws.test.com/v2/transactions?token=zzzzz'; |
||
92 | $this->credentials |
||
93 | ->expects($this->once()) |
||
94 | ->method('getWsUrl') |
||
95 | ->with('/v2/pre-approvals/payment') |
||
96 | ->willReturn($wsUrl); |
||
97 | |||
98 | $response = '<?xml version="1.0" encoding="UTF-8"?><transaction>'; |
||
99 | $response .= '<transactionCode>123456</transactionCode><date>2015-11-19T11:33:54.000-03:00</date>'; |
||
114 |