|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace IBM\Watson\Common; |
|
5
|
|
|
|
|
6
|
|
|
use IBM\Watson\Common\Message\AbstractRequest; |
|
7
|
|
|
use IBM\Watson\Tests\TestCase; |
|
8
|
|
|
use Mockery as m; |
|
9
|
|
|
|
|
10
|
|
|
class AbstractServiceTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private $service; |
|
13
|
|
|
|
|
14
|
|
|
public function setUp() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->service = m::mock('\IBM\Watson\Common\AbstractService')->makePartial(); |
|
17
|
|
|
$this->service->initialize(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testConstruct() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->service = new AbstractServiceTest_MockAbstractService; |
|
23
|
|
|
$this->assertInstanceOf('\GuzzleHttp\Client', $this->service->getProtectedHttpClient()); |
|
24
|
|
|
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Request', $this->service->getProtectedHttpRequest()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetDefaultParameters() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertSame(['username' => null, 'password' => null], $this->service->getDefaultParameters()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGetParameters() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->service->setUsername('adam'); |
|
35
|
|
|
$this->service->setPassword('01234'); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertSame(['username' => 'adam', 'password' => '01234'], $this->service->getParameters()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testInitializeParameters() |
|
41
|
|
|
{ |
|
42
|
|
|
$defaults = [ |
|
43
|
|
|
'username' => 'adam', |
|
44
|
|
|
'password' => [ |
|
45
|
|
|
'01234', |
|
46
|
|
|
'56789' |
|
47
|
|
|
], |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
$this->service->shouldReceive('getDefaultParameters')->once() |
|
|
|
|
|
|
51
|
|
|
->andReturn($defaults); |
|
52
|
|
|
|
|
53
|
|
|
$this->service->initialize(); |
|
54
|
|
|
|
|
55
|
|
|
$expected = [ |
|
56
|
|
|
'username' => 'adam', |
|
57
|
|
|
'password' => '01234', |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
$this->assertSame($expected, $this->service->getParameters()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testUsername() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertSame($this->service, $this->service->setUsername('adam')); |
|
66
|
|
|
$this->assertSame('adam', $this->service->getUsername()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testPassword() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertSame($this->service, $this->service->setPassword('01234')); |
|
72
|
|
|
$this->assertSame('01234', $this->service->getPassword()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testCreateRequest() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->service = new AbstractServiceTest_MockAbstractService; |
|
78
|
|
|
|
|
79
|
|
|
$request = $this->service->callCreateRequest( |
|
80
|
|
|
'\IBM\Watson\Common\AbstractServiceTest_MockAbstractRequest', |
|
81
|
|
|
['username' => 'adam', 'password' => '01234'] |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertSame(['username' => 'adam', 'password' => '01234'], $request->getParameters()); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
// @codingStandardsIgnoreStart |
|
88
|
|
|
class AbstractServiceTest_MockAbstractService extends AbstractService |
|
89
|
|
|
{ |
|
90
|
|
|
public function getProtectedHttpClient() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->httpClient; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getProtectedHttpRequest() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->httpRequest; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function callCreateRequest($class, array $parameters) |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->createRequest($class, $parameters); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
class AbstractServiceTest_MockAbstractRequest extends AbstractRequest |
|
107
|
|
|
{ |
|
108
|
|
|
public function getData() |
|
109
|
|
|
{ |
|
110
|
|
|
} |
|
111
|
|
|
public function sendData($data) |
|
112
|
|
|
{ |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
// @codingStandardsIgnoreEnd |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.