Skip to content

Commit

Permalink
Enhanced tests + ordered them
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskonnertz committed Sep 5, 2017
1 parent a935190 commit ee62b40
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<file>tests/DependenciesTest.php</file>
<file>tests/MainClassTest.php</file>
</testsuite>
</testsuites>
</phpunit>
53 changes: 47 additions & 6 deletions tests/DependenciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// @see http://stackoverflow.com/questions/42811164/class-phpunit-framework-testcase-not-found#answer-42828632
use ChrisKonnertz\DeepLy\HttpClient\CurlHttpClient;
use ChrisKonnertz\DeepLy\Protocol\JsonRpcProtocol;
use ChrisKonnertz\DeepLy\TranslationBag\TranslationBag;

if (!class_exists('\PHPUnit\Framework\TestCase')) {
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
Expand All @@ -29,18 +30,58 @@ protected function getInstance()
public function testGetAndSetSslVerifyPeer()
{
$protocol = new JsonRpcProtocol();

$curlHttpClient = new CurlHttpClient($protocol);

$currentValue = $curlHttpClient->getSslVerifyPeer();
$curlHttpClient->setSslVerifyPeer(true);
$sslVerifyPeer = $curlHttpClient->getSslVerifyPeer();
$this->assertEquals($sslVerifyPeer, true);

$curlHttpClient->setSslVerifyPeer(false);
$sslVerifyPeer = $curlHttpClient->getSslVerifyPeer();
$this->assertEquals($sslVerifyPeer, false);
}

public function testCreateRequestData()
{
$protocol = new JsonRpcProtocol();

$result = $protocol->createRequestData([], ['method' => 'something']);

$this->assertNotNull($result);
}

public function testValidateId()
{
$protocol = new JsonRpcProtocol();

$protocol->setValidateId(true);
$validateId = $protocol->getValidateId();
$this->assertEquals($validateId, true);

$protocol->setValidateId(false);
$validateId = $protocol->getValidateId();
$this->assertEquals($validateId, false);
}

$this->assertNotNull($currentValue);
public function testTranslationAfterResponse()
{
$rawResponseData = '{"id":2,"jsonrpc":"2.0","result":{"source_lang":"EN","source_lang_is_confident":0,'.
'"target_lang":"DE","translations":[{"beams":[{"num_symbols":4,"postprocessed_sentence":"Hallo Welt!"'.
',"score":-5000.23,"totalLogProb":-0.577141},{"num_symbols":5,"postprocessed_sentence":"Hallo, Welt!",'.
'"score":-5001.52,"totalLogProb":-3.94975},{"num_symbols":4,"postprocessed_sentence":"Hello World!"'.
',"score":-5001.55,"totalLogProb":-3.84743}],"timeAfterPreprocessing":0,"timeReceivedFromEndpoint":190,'.
'"timeSentToEndpoint":15,"total_time_endpoint":1}]}}';

$protocol = new JsonRpcProtocol();

$curlHttpClient->setSslVerifyPeer($currentValue);
$responseContent = $protocol->processResponseData($rawResponseData);

$internalValue = $curlHttpClient->getSslVerifyPeer();
$translationBag = new TranslationBag($responseContent);

$this->assertEquals($currentValue, $internalValue);
$translation = $translationBag->getTranslation();

$this->assertEquals($translation, 'Hallo Welt!');
}


}

0 comments on commit ee62b40

Please sign in to comment.