1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IBM\Watson\ToneAnalyzer\tests\Api; |
4
|
|
|
|
5
|
|
|
use IBM\Watson\Common\tests\Api\AbstractTestCase; |
6
|
|
|
use IBM\Watson\ToneAnalyzer\Api\Tone; |
7
|
|
|
use IBM\Watson\ToneAnalyzer\Api\ToneOptions; |
8
|
|
|
use PHPUnit\Framework\Constraint\IsType; |
9
|
|
|
|
10
|
|
|
class ToneTest extends AbstractTestCase |
11
|
|
|
{ |
12
|
|
|
public function testAnalyze() |
13
|
|
|
{ |
14
|
|
|
$this->hydrator->shouldReceive('hydrate')->once()->andReturn(['document_tone' => [], 'sentences_tone' => []]); |
15
|
|
|
$response = $this->getMockResponse('ToneResponse.json'); |
16
|
|
|
$this->httpClient->shouldReceive('sendRequest')->once()->andReturn($response); |
17
|
|
|
|
18
|
|
|
$api = new Tone($this->httpClient, $this->hydrator, $this->requestBuilder); |
19
|
|
|
$response = $api->isHtml(true)->analyze('text', [ |
20
|
|
|
'content_language' => 'en', |
21
|
|
|
'accept_language' => 'fr' |
22
|
|
|
]); |
23
|
|
|
|
24
|
|
|
$this->assertInternalType(IsType::TYPE_ARRAY, $response); |
25
|
|
|
$this->assertArrayHasKey('document_tone', $response); |
26
|
|
|
$this->assertArrayHasKey('sentences_tone', $response); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @expectedException \IBM\Watson\Common\Exception\Api\BadRequestException |
31
|
|
|
* @expectedExceptionMessage Input text exceeded API limit of 131,072 bytes |
32
|
|
|
*/ |
33
|
|
|
public function testInputExceedsLimitException() |
34
|
|
|
{ |
35
|
|
|
$response = $this->getMockResponse('ErrorResponse.json', 400); |
36
|
|
|
$this->httpClient->shouldReceive('sendRequest')->once()->andReturn($response); |
37
|
|
|
|
38
|
|
|
$api = new Tone($this->httpClient, $this->hydrator, $this->requestBuilder); |
39
|
|
|
$api->analyze('LARGE AMOUNT OF TEXT'); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|