Skip to content

Commit

Permalink
updated README and version + updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
I354751 committed Aug 8, 2018
1 parent 6ce31b5 commit 3cb5b73
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 64 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -55,7 +55,7 @@ You can follow us on Twitter at [@recastai](https://twitter.com/recastai) for up

## License

Copyright (c) [2017] [Recast.AI](https://recast.ai)
Copyright (c) [2018] [Recast.AI](https://recast.ai)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "recastai/sdk-php",
"description": "The official PHP SDK Recast.AI",
"version": "3.1.1",
"version": "4.0.0",
"license": "MIT",
"homepage": "https://recast.ai",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions src/apis/Resources/Conversation.php
Expand Up @@ -117,15 +117,15 @@ public function isNegative()
*/
public function isVPositive()
{
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VPOSITIVE);
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VERY_POSITIVE);
}

/**
* @return bool
*/
public function isVNegative()
{
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VNEGATIVE);
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VERY_NEGATIVE);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/apis/Resources/Response.php
Expand Up @@ -221,14 +221,14 @@ public function isNegative()
*/
public function isVPositive()
{
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VPOSITIVE);
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VERY_POSITIVE);
}

/**
* @return bool
*/
public function isVNegative()
{
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VNEGATIVE);
return ($this->sentiment === \RecastAI\Constants::SENTIMENT_VERY_NEGATIVE);
}
}
42 changes: 4 additions & 38 deletions tests/ClientTest.php
Expand Up @@ -47,7 +47,7 @@ public function testClientClassIfAttributesAreOkay()
$this->assertEquals($client->language, $language);
}

public function testTextRequestIfAllOkay()
public function testAnalyseTextIfAllOkay()
{
$callResult = self::jsonResponse();
$res = (Object)[ "body" => ($callResult) ];
Expand All @@ -63,49 +63,15 @@ public function testTextRequestIfAllOkay()
->method('requestPrivate')
->will($this->returnValue($res));
$result = json_decode($res->body);
$response = $stub->textRequest($result->results->source);
$response = $stub->request->analyseText($result->results->source);

$this->assertEquals('200', $response->status);
}

public function testTextRequestIfNoToken()
public function testAnalyseTextIfNoToken()
{
$client = new Client();
$res = $client->textRequest('Hello world');
$this->assertEquals($res, 'Token is missing');
}

public function testFileRequestIfAllOkay()
{
$callResult = self::jsonResponse();

$file = __DIR__ . '/data/file.wav';

if (!file_exists($file)) {
$this->markTestSkipped('Audio test file not found');
}

$token = 'TestToken';
$language = 'en';

$stub = $this->getMockBuilder('RecastAI\Client')
->setConstructorArgs(array($token, $language))
->setMethods(['requestFilePrivate'])
->getMock();

$stub->expects($this->once())
->method('requestFilePrivate')
->will($this->returnValue($callResult));

$response = $stub->fileRequest($file);
$this->assertEquals('200', $response->status);
}

public function testFileRequestIfNoToken()
{
$client = new Client();

$res = $client->fileRequest(__DIR__ . '/data/file.wav');
$res = $client->request->analyseText('Hello world');
$this->assertEquals($res, 'Token is missing');
}
}
19 changes: 11 additions & 8 deletions tests/ConversationTest.php
Expand Up @@ -2,7 +2,7 @@

namespace Tests\RecastAI;

use RecastAI\Conversation;
use RecastAI\apis\Resources\Conversation;

class ConversationTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -13,22 +13,24 @@ protected static function jsonResponse()

public function testConversationClassWithAllOkay()
{
$token = 'TestToken';
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => ($jsonResult) ];
$this->assertInstanceOf('RecastAI\Conversation', new Conversation(($res)));
$this->assertInstanceOf('RecastAI\apis\Resources\Conversation', new Conversation($token, $res));
}

public function testConversationClassAttributes()
{
$token = 'TestToken';
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => ($jsonResult) ];
$conversation = new Conversation(($res));
$conversation = new Conversation($token, json_decode($res->body)->results);
$result = json_decode($res->body);

$this->assertEquals($conversation->conversationToken, $result->results->conversation_token);
$this->assertEquals($conversation->conversation_token, $result->results->conversation_token);
$this->assertEquals($conversation->replies, $result->results->replies);
$this->assertEquals($conversation->action, $result->results->action);
$this->assertEquals($conversation->nextActions, $result->results->next_actions);
$this->assertEquals($conversation->next_actions, $result->results->next_actions);
$this->assertEquals($conversation->memory, $result->results->memory);
$this->assertEquals($conversation->language, $result->results->language);
$this->assertEquals($conversation->processing_language, $result->results->processing_language);
Expand All @@ -37,17 +39,18 @@ public function testConversationClassAttributes()

public function testResponseClassMethods()
{
$token = 'TestToken';
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => ($jsonResult) ];
$result = json_decode($res->body);

$conversation = new Conversation($res);
$conversation = new Conversation($token, json_decode($res->body)->results);

$this->assertEquals($conversation->reply(), $result->results->replies[0]);
$this->assertEquals($conversation->joinedReplies(), join(' ', $result->results->replies));
$this->assertEquals($conversation->joinedReplies('\n'), join('\n', $result->results->replies));
$this->assertEquals($conversation->memory(), $result->results->memory);
$this->assertEquals($conversation->memory('loc'), $result->results->memory->loc);
$this->assertEquals($conversation->getMemory(), $result->results->memory);
$this->assertEquals($conversation->getMemory('loc'), $result->results->memory->loc);
$this->assertEquals($conversation->isVPositive(), false);
$this->assertEquals($conversation->isPositive(), false);
$this->assertEquals($conversation->isNeutral(), true);
Expand Down
4 changes: 2 additions & 2 deletions tests/EntityTest.php
Expand Up @@ -2,7 +2,7 @@

namespace Tests\RecastAI;

use RecastAI\Entity;
use RecastAI\apis\Resources\Entity;

class EntityTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -21,7 +21,7 @@ public function testEntityClassShouldBeInstanciable()
'raw' => 'asparagus',
];

$this->assertInstanceOf('RecastAI\Entity', new Entity('ingredient', $data2));
$this->assertInstanceOf('RecastAI\apis\Resources\Entity', new Entity('ingredient', $data2));
}

public function testEntityClassShouldHaveAttributes()
Expand Down
20 changes: 10 additions & 10 deletions tests/ResponseTest.php
Expand Up @@ -2,7 +2,7 @@

namespace Tests\RecastAI;

use RecastAI\Response;
use RecastAI\apis\Resources\Response;

class ResponseTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -14,17 +14,17 @@ protected static function jsonResponse()
public function testResponseClassWithAllOkay()
{
$jsonResult = self::jsonResponse();
$res = (Object)[ "body" => ($jsonResult) ];
$this->assertInstanceOf('RecastAI\Response', new Response($res));
$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" => ($jsonResult) ];
$result = json_decode($res->body);
$res = (Object)[ "body" => json_decode($jsonResult) ];
$result = $res->body;

$response = new Response($res);
$response = new Response($res->body->results);

$count = count($response->entities, COUNT_RECURSIVE);

Expand All @@ -37,18 +37,18 @@ public function testResponseClassAttributes()
$this->assertEquals($response->version, $result->results->{'version'});
$this->assertEquals($response->timestamp, $result->results->{'timestamp'});
$this->assertEquals($count, 4);
$this->assertInstanceOf('RecastAI\Entity', $response->entities[0]);
$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" => ($jsonResult) ];
$result = json_decode($res->body);
$res = (Object)[ "body" => json_decode($jsonResult) ];
$result = $res->body;

$response = new Response($res);
$response = new Response($res->body->results);

$all = count($response->all('location'));
$get = $response->get('location');
Expand Down

0 comments on commit 3cb5b73

Please sign in to comment.