Skip to content

Commit

Permalink
Original tests restored!
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskonnertz committed Apr 23, 2022
1 parent 66c18ef commit d1acb66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/ChrisKonnertz/DeepLy/DeepLy.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ public function translateFile(
* Tries to detect the language of a text and returns its language code.
* The language of the text has to be one of the supported languages or the result will be incorrect.
* This method might throw an exception, so you should wrap it in a try-catch-block.
* Especially it will throw an exception if the API was not able to auto-detect the language.
* ATTENTION: This request increases the usage statistics of your account!
*
* @param string $text The text you want to analyze
Expand Down
2 changes: 0 additions & 2 deletions tests/DependenciesTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use ChrisKonnertz\DeepLy\HttpClient\CurlHttpClient;
use ChrisKonnertz\DeepLy\Protocol\JsonRpcProtocol;
use ChrisKonnertz\DeepLy\ResponseBag\TranslationBag;

// Ensure backward compatibility
// @see http://stackoverflow.com/questions/42811164/class-phpunit-framework-testcase-not-found#answer-42828632
Expand Down
37 changes: 8 additions & 29 deletions tests/MainClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');

/**
* Class MainClassTest for tests with PHPUnit.
* The focus is here on the main class of this library, ChrisKonnertz\DeePly.
* The focus is here on the main class of this library, the DeepLy class.
*/
class MainClassTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -51,32 +51,22 @@ public function testPing()
// We assume that the ping will be successful.
// If the API is not reachable this will not be the case, of course,
// and the test will fail.
$deepLy->ping();
$duration = $deepLy->ping();

$this->assertIsFloat($duration);
}

public function testDetectLanguage()
{
$deepLy = $this->getInstance();

$languageCode = $deepLy->detectLanguage('Hello world!');
$languageCode = $deepLy->detectLanguage('Hello world! Where do you want to go today?');
$this->assertEquals('EN', $languageCode);

$languageCode = $deepLy->detectLanguage('Hallo Welt!');
$languageCode = $deepLy->detectLanguage('Hallo Welt! Wohin möchtest du heute gehen?');
$this->assertEquals('DE', $languageCode);
}

/**
* @expectedException \ChrisKonnertz\DeepLy\ResponseBag\BagException
* @expectedExceptionCode 130
*/
public function testExceptionDetectionFailed()
{
$deepLy = $this->getInstance();

// DeepL cannot detected the language for this "text" so an exception has to be thrown
$deepLy->detectLanguage('a');
}

public function testTranslation()
{
$deepLy = $this->getInstance();
Expand All @@ -93,17 +83,6 @@ public function testItalianTranslation()
$this->assertEquals('hello', $translatedText);
}

public function testTranslateSentences()
{
$deepLy = $this->getInstance();

$sentences = ['Hello world!', 'What a wonderful world.'];
$sentences = $deepLy->translateSentences($sentences, 'DE', 'EN');

$expectedSentences = ['Hallo Welt!', 'Was für eine wunderbare Welt.'];
$this->assertEquals($expectedSentences, $sentences);
}

public function testTranslationWithLineBreaks()
{
$deepLy = $this->getInstance();
Expand All @@ -112,8 +91,8 @@ public function testTranslationWithLineBreaks()
'Ich habe viel Spaß beim Programmieren.';
$translated = $deepLy->translate($text, 'EN', 'DE');

$expectedTranslated = 'Hello world. How are you, man?'.PHP_EOL.PHP_EOL.
'I have a lot of fun programming.';
$expectedTranslated = 'Hello world. How are you?'.PHP_EOL.PHP_EOL.
'I\'m having a lot of fun programming.';
$this->assertEquals($expectedTranslated, $translated);
}

Expand Down

0 comments on commit d1acb66

Please sign in to comment.