|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: james |
|
5
|
|
|
* Date: 25/07/2018 |
|
6
|
|
|
* Time: 13:12 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace CwsOps\LivePerson\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use CwsOps\LivePerson\Account\Config; |
|
12
|
|
|
use CwsOps\LivePerson\Rest\Request; |
|
13
|
|
|
use CwsOps\LivePerson\Services\OperationalRTService; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
class OperationalRTServiceTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $config; |
|
19
|
|
|
|
|
20
|
|
|
public function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
require_once __DIR__ . '/../Services/MockClient.php'; |
|
23
|
|
|
|
|
24
|
|
|
$accountId = 'foo'; |
|
25
|
|
|
$consumerKey = 'bar'; |
|
26
|
|
|
$consumerSecret = 'biz'; |
|
27
|
|
|
$token = 'baz'; |
|
28
|
|
|
$tokenSecret = 'bee'; |
|
29
|
|
|
$username = 'noo'; |
|
30
|
|
|
$this->config = new Config($accountId, $consumerKey, $consumerSecret, $token, $tokenSecret, $username); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @covers \CwsOps\LivePerson\Services\AbstractService::__construct() |
|
35
|
|
|
* @covers \CwsOps\LivePerson\Services\AbstractService::getRequest() |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testCanConstruct() |
|
38
|
|
|
{ |
|
39
|
|
|
$accountId = 'foo'; |
|
40
|
|
|
$consumerKey = 'bar'; |
|
41
|
|
|
$consumerSecret = 'biz'; |
|
42
|
|
|
$token = 'baz'; |
|
43
|
|
|
$tokenSecret = 'bee'; |
|
44
|
|
|
$username = 'noo'; |
|
45
|
|
|
$this->config = new Config($accountId, $consumerKey, $consumerSecret, $token, $tokenSecret, $username); |
|
46
|
|
|
|
|
47
|
|
|
$service = new OperationalRTService($this->config); |
|
48
|
|
|
|
|
49
|
|
|
$res1 = new \stdClass(); |
|
50
|
|
|
$res1->baseUri = 'test'; |
|
51
|
|
|
|
|
52
|
|
|
$service->getRequest()->setClient(MockClient::getClient([ |
|
53
|
|
|
MockClient::createResponse($res1) |
|
54
|
|
|
])); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertInstanceOf(OperationalRTService::class, $service); |
|
57
|
|
|
$this->assertInstanceOf(Request::class, $service->getRequest()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @covers \CwsOps\LivePerson\Services\OperationalRTService::getResponse() |
|
62
|
|
|
* |
|
63
|
|
|
* @throws \CwsOps\LivePerson\Rest\BuilderLockedException |
|
64
|
|
|
* @throws \CwsOps\LivePerson\Rest\URLNotBuiltException |
|
65
|
|
|
* @throws \CwsOps\LivePerson\Services\RequestNotSentException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testResponseInstanceOfStdClass() |
|
68
|
|
|
{ |
|
69
|
|
|
$service = new OperationalRTService($this->config); |
|
70
|
|
|
|
|
71
|
|
|
$res1 = new \stdClass(); |
|
72
|
|
|
$res1->baseUri = 'test'; |
|
73
|
|
|
|
|
74
|
|
|
$service->getRequest()->setClient(MockClient::getClient([ |
|
75
|
|
|
MockClient::createResponse($res1), |
|
76
|
|
|
MockClient::createResponse($res1) |
|
77
|
|
|
])); |
|
78
|
|
|
|
|
79
|
|
|
$service->agentActivity(60); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertInstanceOf(\stdClass::class, $service->getResponse()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @covers \CwsOps\LivePerson\Services\OperationalRTService::isTimeFrameValid() |
|
86
|
|
|
*/ |
|
87
|
|
|
public function testAgentActivityThrowsExceptionOnInvalidTimeFrame() |
|
88
|
|
|
{ |
|
89
|
|
|
$service = new OperationalRTService($this->config); |
|
90
|
|
|
|
|
91
|
|
|
$res1 = new \stdClass(); |
|
92
|
|
|
$res1->baseUri = 'test'; |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$service->getRequest()->setClient(MockClient::getClient([ |
|
96
|
|
|
MockClient::createResponse($res1), |
|
97
|
|
|
MockClient::createResponse($res1) |
|
98
|
|
|
])); |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
try { |
|
102
|
|
|
$service->agentActivity(5000); |
|
103
|
|
|
} catch (\Exception $e) { |
|
104
|
|
|
$this->assertInstanceOf(\InvalidArgumentException::class, $e); |
|
105
|
|
|
$this->assertEquals('The $timeframe must be between 0 and 1440, you passed 5000', $e->getMessage()); |
|
106
|
|
|
} |
|
107
|
|
|
try { |
|
108
|
|
|
$service->agentActivity(-1); |
|
109
|
|
|
} catch (\Exception $e) { |
|
110
|
|
|
$this->assertInstanceOf(\InvalidArgumentException::class, $e); |
|
111
|
|
|
$this->assertEquals('The $timeframe must be between 0 and 1440, you passed -1', $e->getMessage()); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @covers \CwsOps\LivePerson\Services\OperationalRTService::isIntervalValid() |
|
117
|
|
|
*/ |
|
118
|
|
|
public function testThrowsExceptionOnInvalidInterval() |
|
119
|
|
|
{ |
|
120
|
|
|
$service = new OperationalRTService($this->config); |
|
121
|
|
|
|
|
122
|
|
|
$res1 = new \stdClass(); |
|
123
|
|
|
$res1->baseUri = 'test'; |
|
124
|
|
|
|
|
125
|
|
|
$service->getRequest()->setClient(MockClient::getClient([ |
|
126
|
|
|
MockClient::createResponse($res1), |
|
127
|
|
|
MockClient::createResponse($res1) |
|
128
|
|
|
])); |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
try { |
|
132
|
|
|
// Interval larger, but dividable by 60, Should fail. |
|
133
|
|
|
$service->agentActivity(60, [12345, 12345], 120); |
|
134
|
|
|
} catch (\Exception $e) { |
|
135
|
|
|
$this->assertInstanceOf(\InvalidArgumentException::class, $e); |
|
136
|
|
|
$this->assertEquals('The $interval you passed was not valid or not dividable by the $timeframe (60), you passed 120', $e->getMessage()); |
|
137
|
|
|
} |
|
138
|
|
|
try { |
|
139
|
|
|
// Interval smaller, but not dividable by 60, Should fail. |
|
140
|
|
|
$service->agentActivity(60, [12345, 12345], 34); |
|
141
|
|
|
} catch (\Exception $e) { |
|
142
|
|
|
$this->assertInstanceOf(\InvalidArgumentException::class, $e); |
|
143
|
|
|
$this->assertEquals('The $interval you passed was not valid or not dividable by the $timeframe (60), you passed 34', $e->getMessage()); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|