1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HelePartnerSyncApi; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
|
7
|
|
|
class ClientTest extends PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
private $secret = 'secret'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $method = 'foo'; |
19
|
|
|
|
20
|
|
|
public function testSuccess() |
21
|
|
|
{ |
22
|
|
|
$data = array($this->method => 'bar'); |
23
|
|
|
$method = $this->getMethodMock($data); |
24
|
|
|
$requestFactory = $this->getRequestFactoryMock(); |
25
|
|
|
|
26
|
|
|
$client = new Client($this->secret, $requestFactory); |
27
|
|
|
$client->registerMethod($method); |
28
|
|
|
|
29
|
|
|
$response = $client->run(); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($response->isSuccessful()); |
32
|
|
|
$this->assertSame($data, $response->getData()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $dataToReturn |
37
|
|
|
* @return \HelePartnerSyncApi\Method\Method |
38
|
|
|
*/ |
39
|
|
|
protected function getMethodMock(array $dataToReturn) |
40
|
|
|
{ |
41
|
|
|
$method = $this->getMockBuilder('HelePartnerSyncApi\Method\Method') |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->getMock(); |
44
|
|
|
|
45
|
|
|
$method->expects(self::once()) |
46
|
|
|
->method('call') |
47
|
|
|
->willReturn($dataToReturn); |
48
|
|
|
|
49
|
|
|
$method->expects(self::once()) |
50
|
|
|
->method('getName') |
51
|
|
|
->willReturn($this->method); |
52
|
|
|
|
53
|
|
|
return $method; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return \HelePartnerSyncApi\Request\RequestFactory |
58
|
|
|
*/ |
59
|
|
|
private function getRequestFactoryMock() |
60
|
|
|
{ |
61
|
|
|
$factory = $this->getMockBuilder('HelePartnerSyncApi\Request\RequestFactory') |
62
|
|
|
->getMock(); |
63
|
|
|
|
64
|
|
|
$factory->expects(self::once()) |
65
|
|
|
->method('createRequest') |
66
|
|
|
->willReturn($this->getRequestMock()); |
67
|
|
|
|
68
|
|
|
return $factory; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \HelePartnerSyncApi\Request\Request |
73
|
|
|
*/ |
74
|
|
|
private function getRequestMock() |
75
|
|
|
{ |
76
|
|
|
$request = $this->getMockBuilder('HelePartnerSyncApi\Request\Request') |
77
|
|
|
->disableOriginalConstructor() |
78
|
|
|
->getMock(); |
79
|
|
|
|
80
|
|
|
$request->expects(self::atLeastOnce()) |
81
|
|
|
->method('getMethod') |
82
|
|
|
->willReturn($this->method); |
83
|
|
|
|
84
|
|
|
return $request; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|