blob: b1a3d77ed610d3d804a24ebd40000947e2984895 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
<?php
namespace Cardinity\Tests;
use Cardinity\Client;
use Cardinity\Method\Payment;
class ErrorTest extends ClientTestCase
{
public function testErrorResultObjectForErrorResponse()
{
$method = $this
->getMockBuilder('Cardinity\Method\Payment\Get')
->disableOriginalConstructor()
->getMock()
;
$method->method('getAction')->willReturn('payments');
$method->method('getAttributes')->willReturn([]);
$method->method('getMethod')->willReturn(Payment\Get::POST);
try {
$this->client->call($method);
} catch (\Cardinity\Exception\ValidationFailed $e) {
$result = $e->getResult();
$this->assertInstanceOf('Cardinity\Method\Error', $result);
$this->assertSame('https://developers.cardinity.com/api/v1/#400', $result->getType());
$this->assertSame('Validation Failed', $result->getTitle());
$this->assertContains('validation errors', $result->getDetail());
$this->assertTrue(is_array($result->getErrors()));
$this->assertNotEmpty($result->getErrors());
}
}
/**
* @expectedException Cardinity\Exception\Unauthorized
*/
public function testUnauthorizedResponse()
{
$client = Client::create([
'consumerKey' => 'no',
'consumerSecret' => 'yes',
]);
$method = new Payment\Get('xxxyyy');
$client->call($method);
}
/**
* @expectedException Cardinity\Exception\ValidationFailed
*/
public function testBadRequest()
{
$method = $this
->getMockBuilder('Cardinity\Method\Payment\Get')
->disableOriginalConstructor()
->getMock()
;
$method->method('getAction')->willReturn('payments');
$method->method('getAttributes')->willReturn([]);
$method->method('getMethod')->willReturn(Payment\Get::POST);
$this->client->call($method);
}
/**
* @expectedException Cardinity\Exception\NotFound
*/
public function testNotFound()
{
$method = $this
->getMockBuilder('Cardinity\Method\Payment\Get')
->disableOriginalConstructor()
->getMock()
;
$method->method('getAction')->willReturn('my_dreamy_action');
$method->method('getAttributes')->willReturn([]);
$method->method('getMethod')->willReturn(Payment\Get::POST);
$this->client->call($method);
}
/**
* @expectedException Cardinity\Exception\MethodNotAllowed
*/
public function testMethodNotAllowed()
{
$method = $this
->getMockBuilder('Cardinity\Method\Payment\Get')
->disableOriginalConstructor()
->getMock()
;
$method->method('getAction')->willReturn('payments');
$method->method('getAttributes')->willReturn([]);
$method->method('getMethod')->willReturn('DELETE');
$this->client->call($method);
}
}
|