1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Purchases\Transactions; |
3
|
|
|
|
4
|
|
|
use PHPSC\PagSeguro\Credentials; |
5
|
|
|
use PHPSC\PagSeguro\Client\Client; |
6
|
|
|
use PHPSC\PagSeguro\Environment; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class LocatorTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Credentials |
15
|
|
|
*/ |
16
|
|
|
protected $credentials; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Client|\PHPUnit_Framework_MockObject_MockObject |
20
|
|
|
*/ |
21
|
|
|
protected $client; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Decoder|\PHPUnit_Framework_MockObject_MockObject |
25
|
|
|
*/ |
26
|
|
|
protected $decoder; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Transaction|\PHPUnit_Framework_MockObject_MockObject |
30
|
|
|
*/ |
31
|
|
|
private $transaction; |
32
|
|
|
|
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
$environment = $this->getMockForAbstractClass(Environment::class); |
36
|
|
|
|
37
|
|
|
$environment->expects($this->any()) |
38
|
|
|
->method('getHost') |
39
|
|
|
->willReturn('test.com'); |
40
|
|
|
|
41
|
|
|
$environment->expects($this->any()) |
42
|
|
|
->method('getWsHost') |
43
|
|
|
->willReturn('ws.test.com'); |
44
|
|
|
|
45
|
|
|
$this->credentials = new Credentials('[email protected]', 't', $environment); |
46
|
|
|
|
47
|
|
|
$this->client = $this->createMock(Client::class); |
48
|
|
|
$this->decoder = $this->createMock(Decoder::class); |
49
|
|
|
$this->transaction = $this->createMock(Transaction::class); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
*/ |
55
|
|
|
public function getByCodeShouldDoAGetRequestAddingCredentialsData() |
56
|
|
|
{ |
57
|
|
|
$xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />'); |
58
|
|
|
|
59
|
|
|
$this->client->expects($this->once()) |
60
|
|
|
->method('get') |
61
|
|
|
->with('https://ws.test.com/v2/transactions/1?email=a%40a.com&token=t') |
62
|
|
|
->willReturn($xml); |
63
|
|
|
|
64
|
|
|
$this->decoder->expects($this->once()) |
65
|
|
|
->method('decode') |
66
|
|
|
->with($xml) |
67
|
|
|
->willReturn($this->transaction); |
68
|
|
|
|
69
|
|
|
$service = new Locator($this->credentials, $this->client, $this->decoder); |
70
|
|
|
|
71
|
|
|
$this->assertSame($this->transaction, $service->getByCode(1)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @test |
76
|
|
|
*/ |
77
|
|
|
public function getByNotificationShouldDoAGetRequestAddingCredentialsData() |
78
|
|
|
{ |
79
|
|
|
$xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><data />'); |
80
|
|
|
|
81
|
|
|
$this->client->expects($this->once()) |
82
|
|
|
->method('get') |
83
|
|
|
->with('https://ws.test.com/v2/transactions/notifications/1?email=a%40a.com&token=t') |
84
|
|
|
->willReturn($xml); |
85
|
|
|
|
86
|
|
|
$this->decoder->expects($this->once()) |
87
|
|
|
->method('decode') |
88
|
|
|
->with($xml) |
89
|
|
|
->willReturn($this->transaction); |
90
|
|
|
|
91
|
|
|
$service = new Locator($this->credentials, $this->client, $this->decoder); |
92
|
|
|
|
93
|
|
|
$this->assertSame($this->transaction, $service->getByNotification(1)); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|