| @@ 8-23 (lines=16) @@ | ||
| 5 | use IBM\Watson\Common\tests\Api\AbstractTestCase; |
|
| 6 | use IBM\Watson\ToneAnalyzer\Model\SentenceAnalysis; |
|
| 7 | ||
| 8 | class SentenceAnalysisTest extends AbstractTestCase |
|
| 9 | { |
|
| 10 | public function testSentences() |
|
| 11 | { |
|
| 12 | $response = $this->getMockResponse('ToneResponse.json'); |
|
| 13 | $data = json_decode($response->getBody(), true); |
|
| 14 | ||
| 15 | $sentence = $data['sentences_tone'][0]; |
|
| 16 | ||
| 17 | $analysis = SentenceAnalysis::create($sentence); |
|
| 18 | ||
| 19 | $this->assertSame(0, $analysis->getId()); |
|
| 20 | $this->assertSame('Team, I know that times are tough!', $analysis->getText()); |
|
| 21 | $this->assertNotEmpty($analysis->getTones()); |
|
| 22 | } |
|
| 23 | } |
|
| 24 | ||
| @@ 8-23 (lines=16) @@ | ||
| 5 | use IBM\Watson\Common\tests\Api\AbstractTestCase; |
|
| 6 | use IBM\Watson\ToneAnalyzer\Model\ToneScore; |
|
| 7 | ||
| 8 | class ToneScoreTest extends AbstractTestCase |
|
| 9 | { |
|
| 10 | public function testToneScore() |
|
| 11 | { |
|
| 12 | $response = $this->getMockResponse('ToneResponse.json'); |
|
| 13 | $data = json_decode($response->getBody(), true); |
|
| 14 | ||
| 15 | $toneData = $data['document_tone']['tones'][0]; |
|
| 16 | ||
| 17 | $toneScore = ToneScore::create($toneData); |
|
| 18 | ||
| 19 | $this->assertSame(0.6165, $toneScore->getScore()); |
|
| 20 | $this->assertSame('sadness', $toneScore->getId()); |
|
| 21 | $this->assertSame('Sadness', $toneScore->getName()); |
|
| 22 | } |
|
| 23 | } |
|
| 24 | ||