TranslationTest::testRawResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
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 TranslationTest 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 testTranslationEquality()
15
    {
16
        $resultOne = TranslateClient::translate('en', 'ka', 'Hello');
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

16
        /** @scrutinizer ignore-call */ 
17
        $resultOne = TranslateClient::translate('en', 'ka', 'Hello');
Loading history...
Unused Code introduced by
The call to Stichoza\GoogleTranslate...lateClient::translate() has too many arguments starting with 'ka'. ( Ignorable by Annotation )

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

16
        /** @scrutinizer ignore-call */ 
17
        $resultOne = TranslateClient::translate('en', 'ka', 'Hello');

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...
17
        $resultTwo = $this->tr->setSource('en')->setTarget('ka')->translate('Hello');
18
19
        $this->assertEquals($resultOne, $resultTwo, 'გამარჯობა');
20
    }
21
22
    public function testArrayTranslation()
23
    {
24
        $this->tr->setSource('en')->setTarget('ka');
25
26
        $resultCat = $this->tr->translate('cat');
27
        $resultDog = $this->tr->translate('dog');
28
        $resultFish = $this->tr->translate('fish');
29
30
        $arrayResults = $this->tr->translate(['cat', 'dog', 'fish']);
31
        $arrayZesults = TranslateClient::translate('en', 'ka', ['cat', 'dog', 'fish']);
0 ignored issues
show
Unused Code introduced by
The call to Stichoza\GoogleTranslate...lateClient::translate() has too many arguments starting with 'ka'. ( Ignorable by Annotation )

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

31
        /** @scrutinizer ignore-call */ 
32
        $arrayZesults = TranslateClient::translate('en', 'ka', ['cat', 'dog', 'fish']);

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...
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

31
        /** @scrutinizer ignore-call */ 
32
        $arrayZesults = TranslateClient::translate('en', 'ka', ['cat', 'dog', 'fish']);
Loading history...
32
33
        $this->assertEquals($resultCat, $arrayResults[0], 'კატა');
34
        $this->assertEquals($resultDog, $arrayResults[1], 'ძაღლი');
35
        $this->assertEquals($resultFish, $arrayResults[2], 'თევზი');
36
37
        $this->assertEquals($resultCat, $arrayZesults[0], 'კატა');
38
        $this->assertEquals($resultDog, $arrayZesults[1], 'ძაღლი');
39
        $this->assertEquals($resultFish, $arrayZesults[2], 'თევზი');
40
    }
41
42
    public function testRawResponse()
43
    {
44
        $rawResult = $this->tr->getResponse('cat');
45
46
        $this->assertTrue(is_array($rawResult), 'Method getResponse() should return an array.');
47
    }
48
}
49