1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bobbyshaw\WatsonVisualRecognition\Tests\Message; |
4
|
|
|
|
5
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Client; |
6
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Message\DeleteClassifierRequest; |
7
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Message\Response; |
8
|
|
|
use Bobbyshaw\WatsonVisualRecognition\Tests\Base; |
9
|
|
|
use GuzzleHttp\Psr7\Request; |
10
|
|
|
use GuzzleHttp\Psr7\Response as HttpResponse; |
11
|
|
|
use GuzzleHttp\Psr7\Uri; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class GetClassifiersRequestTest |
15
|
|
|
* @package Bobbyshaw\WatsonVisualRecognition\Tests\Message |
16
|
|
|
*/ |
17
|
|
|
class DeleteClassifierRequestTest extends Base |
18
|
|
|
{ |
19
|
|
|
/** @var Client */ |
20
|
|
|
private $client; |
21
|
|
|
private $config; |
22
|
|
|
private $username = 'username'; |
23
|
|
|
private $password = 'password'; |
24
|
|
|
private $version = '2015-12-02'; |
25
|
|
|
private $classifierId = 'Magenta'; |
26
|
|
|
|
27
|
|
View Code Duplication |
public function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->config = array( |
30
|
|
|
'username' => $this->username, |
31
|
|
|
'password' => $this->password, |
32
|
|
|
'version' => $this->version |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$this->client = new Client(); |
36
|
|
|
$this->client->initialize($this->config); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Test that params are as expected |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function testGetData() |
43
|
|
|
{ |
44
|
|
|
/** @var DeleteClassifierRequest $request */ |
45
|
|
|
$request = $this->client->deleteClassifier(['classifier_id' => $this->classifierId]); |
46
|
|
|
|
47
|
|
|
$this->assertEquals(array_merge($this->config, ['classifier_id' => $this->classifierId]), $request->getData()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Test the delete classifier function HTTP request |
52
|
|
|
*/ |
53
|
|
|
public function testDeleteClassifier() |
54
|
|
|
{ |
55
|
|
|
$container = []; |
56
|
|
|
$guzzle = $this->getMockHttpClientWithHistoryAndResponses( |
57
|
|
|
$container, |
58
|
|
|
[new HttpResponse(200, [], '{}')] |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->client = new Client($guzzle); |
63
|
|
|
$this->client->initialize(['username' => $this->username, 'password' => $this->password]); |
64
|
|
|
|
65
|
|
|
/** @var DeleteClassifierRequest $request */ |
66
|
|
|
$classifierRequest = $this->client->deleteClassifier(['classifier_id' => $this->classifierId]); |
67
|
|
|
|
68
|
|
|
/** @var Response $response */ |
69
|
|
|
$classifierRequest->send(); |
70
|
|
|
|
71
|
|
|
// One request should be sent |
72
|
|
|
$this->assertCount(1, $container); |
73
|
|
|
|
74
|
|
|
$transaction = $container[0]; |
75
|
|
|
|
76
|
|
|
/** @var Request $request */ |
77
|
|
|
$request = $transaction['request']; |
78
|
|
|
|
79
|
|
|
/** @var Uri $uri */ |
80
|
|
|
$uri = $request->getUri(); |
81
|
|
|
|
82
|
|
|
// Check data is passed in as query parameter and not as a post |
83
|
|
|
$this->assertEquals('DELETE', $request->getMethod()); |
84
|
|
|
|
85
|
|
|
// Check path |
86
|
|
|
$this->assertEquals('/visual-recognition-beta/api/v2/classifiers/' . $this->classifierId, $uri->getPath()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Test deleteClassifier failed auth is handled appropriately |
91
|
|
|
* |
92
|
|
|
* @expectedException \Bobbyshaw\WatsonVisualRecognition\Exceptions\AuthException |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public function testDeleteClassifierFailedAuthResponse() |
95
|
|
|
{ |
96
|
|
|
$container = []; |
97
|
|
|
$response = $this->getMockHttpResponse('FailedAuth.txt', 401); |
98
|
|
|
$httpClient = $this->getMockHttpClientWithHistoryAndResponses($container, [$response]); |
99
|
|
|
|
100
|
|
|
$this->client = new Client($httpClient); |
101
|
|
|
$this->client->initialize(['username' => $this->username, 'password' => $this->password]); |
102
|
|
|
|
103
|
|
|
/** @var DeleteClassifierRequest $request */ |
104
|
|
|
$request = $this->client->deleteClassifier(['classifier_id' => $this->classifierId]); |
105
|
|
|
$request->send(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|