LanguageDetectionTest::testSingleWord()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Stichoza\GoogleTranslate\Tests;
4
5
use Stichoza\GoogleTranslate\TranslateClient;
6
7
class LanguageDetectionTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
{
9
    public function setUp()
10
    {
11
        $this->tr = new TranslateClient();
0 ignored issues
show
Bug Best Practice introduced by
The property tr does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
12
    }
13
14
    public function testSingleWord()
15
    {
16
        $this->tr->translate('გამარჯობა');
17
        $this->assertEquals($this->tr->getLastDetectedSource(), 'ka');
18
19
        $this->tr->translate('Cześć');
20
        $this->assertEquals($this->tr->getLastDetectedSource(), 'pl');
21
    }
22
23
    public function testSingleSentence()
24
    {
25
        $this->tr->translate('იყო არაბეთს როსტევან');
26
        $this->assertEquals($this->tr->getLastDetectedSource(), 'ka');
27
28
        $this->tr->translate('Путин хуйло');
29
        $this->assertEquals($this->tr->getLastDetectedSource(), 'ru');
30
    }
31
32
    public function testMultipleSentence()
33
    {
34
        $this->tr->translate('ჩემი ხატია სამშობლო. სახატე - მთელი ქვეყანა. განათებული მთა-ბარი.');
35
        $this->assertEquals($this->tr->getLastDetectedSource(), 'ka');
36
37
        $this->tr->translate('Ще не вмерла Україна, И слава, и воля! Ще намъ, браття-молодці, Усміхнеться доля!');
38
        $this->assertEquals($this->tr->getLastDetectedSource(), 'uk');
39
    }
40
41
    public function testStaticAndNonStaticDetection()
42
    {
43
        $this->tr->translate('გამარჯობა');
44
45
        TranslateClient::translate(null, 'en', 'Cześć');
0 ignored issues
show
Bug Best Practice introduced by
The method Stichoza\GoogleTranslate...lateClient::translate() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        TranslateClient::/** @scrutinizer ignore-call */ 
46
                         translate(null, 'en', 'Cześć');
Loading history...
Unused Code introduced by
The call to Stichoza\GoogleTranslate...lateClient::translate() has too many arguments starting with 'en'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        TranslateClient::/** @scrutinizer ignore-call */ 
46
                         translate(null, 'en', 'Cześć');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
46
        $this->assertEquals($this->tr->getLastDetectedSource(), 'pl');
47
        $this->assertEquals(TranslateClient::getLastDetectedSource(), 'pl');
0 ignored issues
show
Bug Best Practice introduced by
The method Stichoza\GoogleTranslate...getLastDetectedSource() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $this->assertEquals(TranslateClient::/** @scrutinizer ignore-call */ getLastDetectedSource(), 'pl');
Loading history...
48
49
        $this->tr->translate('გამარჯობა');
50
        $this->assertEquals($this->tr->getLastDetectedSource(), 'ka');
51
        $this->assertEquals(TranslateClient::getLastDetectedSource(), 'ka');
52
    }
53
}
54