forked from SAP-archive/SDK-PHP
/
ResponseTest.php
76 lines (63 loc) · 3.13 KB
/
ResponseTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Tests\RecastAI;
use RecastAI\apis\Resources\Response;
class ResponseTest extends \PHPUnit_Framework_TestCase
{
protected static function jsonResponse()
{
return file_get_contents(__DIR__ . '/data/Request.json');
}
public function testResponseClassWithAllOkay()
{
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => json_decode($jsonResult) ];
$this->assertInstanceOf('RecastAI\apis\Resources\Response', new Response($res->body->results));
}
public function testResponseClassAttributes()
{
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => json_decode($jsonResult) ];
$result = $res->body;
$response = new Response($res->body->results);
$count = count($response->entities, COUNT_RECURSIVE);
$this->assertEquals($response->act, $result->results->{'act'});
$this->assertEquals($response->type, $result->results->{'type'});
$this->assertEquals($response->source, $result->results->{'source'});
$this->assertEquals($response->sentiment, $result->results->{'sentiment'});
$this->assertEquals($response->language, $result->results->{'language'});
$this->assertEquals($response->processing_language, $result->results->{'processing_language'});
$this->assertEquals($response->version, $result->results->{'version'});
$this->assertEquals($response->timestamp, $result->results->{'timestamp'});
$this->assertEquals($count, 4);
$this->assertInstanceOf('RecastAI\apis\Resources\Entity', $response->entities[0]);
$this->assertInternalType('array', $response->entities);
$this->assertInternalType('array', $response->intents);
}
public function testResponseClassMethods()
{
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => json_decode($jsonResult) ];
$result = $res->body;
$response = new Response($res->body->results);
$all = count($response->all('location'));
$get = $response->get('location');
$this->assertEquals($response->intent(), $result->results->{'intents'}[0]);
$this->assertEquals($all, 2);
$this->assertEquals('location', $get->name);
$this->assertEquals($response->isAssert(), false);
$this->assertEquals($response->isCommand(), false);
$this->assertEquals($response->isWhQuery(), true);
$this->assertEquals($response->isYnQuery(), false);
$this->assertEquals($response->isAbbreviation(), false);
$this->assertEquals($response->isEntity(), false);
$this->assertEquals($response->isDescription(), true);
$this->assertEquals($response->isHuman(), false);
$this->assertEquals($response->isLocation(), false);
$this->assertEquals($response->isNumber(), false);
$this->assertEquals($response->isVPositive(), false);
$this->assertEquals($response->isPositive(), false);
$this->assertEquals($response->isNeutral(), true);
$this->assertEquals($response->isNegative(), false);
$this->assertEquals($response->isVNegative(), false);
}
}