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

ToneTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAnalyze() 0 16 1
A testInputExceedsLimitException() 0 8 1
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