1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Client; |
3
|
|
|
|
4
|
|
|
use GuzzleHttp\ClientInterface; |
5
|
|
|
use GuzzleHttp\Client as HttpClient; |
6
|
|
|
use Psr\Http\Message\RequestInterface; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class ClientTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var HttpClient|\PHPUnit_Framework_MockObject_MockObject |
13
|
|
|
*/ |
14
|
|
|
protected $httpClient; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject |
18
|
|
|
*/ |
19
|
|
|
protected $request; |
20
|
|
|
private $response; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->httpClient = $this->createMock(ClientInterface::class); |
25
|
|
|
$this->request = $this->createMock(RequestInterface::class); |
26
|
|
|
$this->response = $this->createMock(ResponseInterface::class); |
27
|
|
|
|
28
|
|
|
$xml = <<<'XML' |
29
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
30
|
|
|
<checkout> |
31
|
|
|
<code>8CF4BE7DCECEF0F004A6DFA0A8243412</code> |
32
|
|
|
<date>2010-12-02T10:11:28.000-02:00</date> |
33
|
|
|
</checkout> |
34
|
|
|
XML; |
35
|
|
|
|
36
|
|
|
$this->response->expects($this->once()) |
37
|
|
|
->method('getBody') |
38
|
|
|
->willReturn($xml); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @test |
43
|
|
|
*/ |
44
|
|
|
public function postShouldSendTheBodyAsXml() |
45
|
|
|
{ |
46
|
|
|
$client = new Client($this->httpClient); |
47
|
|
|
$xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><checkout/>'); |
48
|
|
|
|
49
|
|
|
$this->httpClient->expects($this->once()) |
50
|
|
|
->method('request') |
51
|
|
|
->with( |
52
|
|
|
'POST', |
53
|
|
|
'/test', |
54
|
|
|
[ |
55
|
|
|
'headers' => ['Content-Type' => 'application/xml; charset=UTF-8'], |
56
|
|
|
'body' => $xml->asXML(), |
57
|
|
|
'verify' => false |
58
|
|
|
] |
59
|
|
|
)->willReturn($this->response); |
60
|
|
|
|
61
|
|
|
$this->assertInstanceOf('SimpleXMLElement', $client->post('/test', $xml)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @test |
66
|
|
|
*/ |
67
|
|
|
public function getShouldConfigureHeaders() |
68
|
|
|
{ |
69
|
|
|
$client = new Client($this->httpClient); |
70
|
|
|
|
71
|
|
|
$this->httpClient->expects($this->once()) |
72
|
|
|
->method('request') |
73
|
|
|
->with('GET', '/test?name=Test', ['verify' => false]) |
74
|
|
|
->willReturn($this->response); |
75
|
|
|
|
76
|
|
|
$this->assertInstanceOf('SimpleXMLElement', $client->get('/test?name=Test')); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|