|
1
|
|
|
<?php |
|
2
|
|
|
namespace PHPSC\PagSeguro\Requests\PreApprovals; |
|
3
|
|
|
|
|
4
|
|
|
use PHPSC\PagSeguro\Client\Client; |
|
5
|
|
|
use PHPSC\PagSeguro\Credentials; |
|
6
|
|
|
use PHPSC\PagSeguro\Requests\Redirection; |
|
7
|
|
|
use SimpleXMLElement; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Renato Moura <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class PreApprovalServiceTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testCreateRequestBuilderShouldDoReturnObject() |
|
15
|
|
|
{ |
|
16
|
|
|
$credentials = $this->createMock(Credentials::class); |
|
17
|
|
|
$client = $this->createMock(Client::class); |
|
18
|
|
|
$serializer = $this->createMock(RequestSerializer::class); |
|
19
|
|
|
|
|
20
|
|
|
$service = new PreApprovalService($credentials, $client, $serializer); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertAttributeEquals($serializer, 'serializer', $service); |
|
23
|
|
|
$this->assertAttributeEquals($credentials, 'credentials', $service); |
|
24
|
|
|
$this->assertAttributeEquals($client, 'client', $service); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals(new RequestBuilder(true), $service->createRequestBuilder()); |
|
27
|
|
|
$this->assertEquals(new RequestBuilder(false), $service->createRequestBuilder(false)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testAproveShouldReturningTheRedirection() |
|
31
|
|
|
{ |
|
32
|
|
|
$request = new Request; |
|
33
|
|
|
$response = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><response/>'); |
|
34
|
|
|
$xmlSerialize = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><request/>'); |
|
35
|
|
|
$redirect = $this->createMock(Redirection::class); |
|
36
|
|
|
|
|
37
|
|
|
$credentials = $this->createMock(Credentials::class); |
|
38
|
|
|
$client = $this->createMock(Client::class); |
|
39
|
|
|
$serializer = $this->createMock(RequestSerializer::class); |
|
40
|
|
|
|
|
41
|
|
|
$serializer->expects($this->once()) |
|
42
|
|
|
->method('serialize') |
|
43
|
|
|
->willReturn($xmlSerialize); |
|
44
|
|
|
|
|
45
|
|
|
$service = $this->getMockBuilder(PreApprovalService::class) |
|
46
|
|
|
->setMethods(['post', 'getRedirection']) |
|
47
|
|
|
->setConstructorArgs([$credentials, $client, $serializer]) |
|
48
|
|
|
->disableOriginalClone() |
|
49
|
|
|
->getMock(); |
|
50
|
|
|
|
|
51
|
|
|
$service->expects($this->once()) |
|
52
|
|
|
->method('post') |
|
53
|
|
|
->with(PreApprovalService::ENDPOINT, $xmlSerialize) |
|
54
|
|
|
->willReturn($response); |
|
55
|
|
|
|
|
56
|
|
|
$service->expects($this->once()) |
|
57
|
|
|
->method('getRedirection') |
|
58
|
|
|
->with($response) |
|
59
|
|
|
->willReturn($redirect); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals($redirect, $service->approve($request)); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|