Completed
Push — develop ( c8d2e9...9b1d71 )
by Adam
03:00
created

ToneTest::testAnalyze()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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