1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IBM\Watson\ToneAnalyzer\tests\Model; |
4
|
|
|
|
5
|
|
|
use IBM\Watson\Common\tests\Api\AbstractTestCase; |
6
|
|
|
use IBM\Watson\ToneAnalyzer\Model\UtteranceAnalyses; |
7
|
|
|
use IBM\Watson\ToneAnalyzer\Model\UtteranceAnalysis; |
8
|
|
|
use PHPUnit\Framework\Constraint\IsType; |
9
|
|
|
|
10
|
|
|
class UtteranceAnalysisTest extends AbstractTestCase |
11
|
|
|
{ |
12
|
|
|
private $response; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
$this->response = $this->getMockResponse('ToneChatResponse.json'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
|
21
|
|
View Code Duplication |
public function testGetError() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$data = json_decode($this->response->getBody(), true); |
24
|
|
|
|
25
|
|
|
$utteranceAnalysis = UtteranceAnalysis::create($data[UtteranceAnalyses::KEY_TONE][0]); |
26
|
|
|
|
27
|
|
|
$this->assertNull($utteranceAnalysis->getError()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function testGetId() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$data = json_decode($this->response->getBody(), true); |
33
|
|
|
|
34
|
|
|
$utteranceAnalysis = UtteranceAnalysis::create($data[UtteranceAnalyses::KEY_TONE][0]); |
35
|
|
|
|
36
|
|
|
$this->assertSame(0, $utteranceAnalysis->getId()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function testGetText() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$data = json_decode($this->response->getBody(), true); |
42
|
|
|
|
43
|
|
|
$utteranceAnalysis = UtteranceAnalysis::create($data[UtteranceAnalyses::KEY_TONE][0]); |
44
|
|
|
|
45
|
|
|
$this->assertSame('Hello, I\'m having a problem with your product.', $utteranceAnalysis->getText()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function testCreate() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$data = json_decode($this->response->getBody(), true); |
51
|
|
|
|
52
|
|
|
$utteranceAnalysis = UtteranceAnalysis::create($data[UtteranceAnalyses::KEY_TONE][0]); |
53
|
|
|
|
54
|
|
|
$this->assertInstanceOf(UtteranceAnalysis::class, $utteranceAnalysis); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function testGetTones() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$data = json_decode($this->response->getBody(), true); |
60
|
|
|
|
61
|
|
|
$utteranceAnalysis = UtteranceAnalysis::create($data[UtteranceAnalyses::KEY_TONE][0]); |
62
|
|
|
|
63
|
|
|
$this->assertInternalType(IsType::TYPE_ARRAY, $utteranceAnalysis->getTones()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.