Minor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Happyr\AutoFallbackTranslationBundle\Tests\Unit\Translator;
4
5
use Happyr\AutoFallbackTranslationBundle\Service\TranslatorService;
6
use Happyr\AutoFallbackTranslationBundle\Translator\FallbackTranslator;
7
8
/**
9
 * @author Tobias Nyholm <[email protected]>
10
 */
11
class FallbackTranslatorTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testTranslateWithSubstitutedParameters()
14
    {
15
        $method = new \ReflectionMethod(FallbackTranslator::class, 'translateWithSubstitutedParameters');
16
        $method->setAccessible(true);
17
18
        $translator = $this->getMockBuilder(TranslatorService::class)->getMock();
19
        $translator->method('translate')->will($this->returnArgument(0));
20
21
        $service = $this->getMockBuilder(FallbackTranslator::class)
22
            ->disableOriginalConstructor()
23
            ->setMethods(['getTranslatorService'])
24
            ->getMock();
25
        $service->expects($this->any())->method('getTranslatorService')->willReturn($translator);
26
27
        // One parameter test
28
        $result = $method->invoke($service, 'abc bar abc', 'en', ['%foo%' => 'bar']);
29
        $this->assertEquals('abc bar abc', $result);
30
31
        // Two parameters test
32
        $result = $method->invoke($service, 'abc bar abc baz', 'en', ['%foo%' => 'bar', '%biz%' => 'baz']);
33
        $this->assertEquals('abc bar abc baz', $result);
34
35
        // Test with object
36
        $result = $method->invoke($service, 'abc object abc', 'en', ['%foo%' => new Minor('object')]);
37
        $this->assertEquals('abc object abc', $result);
38
    }
39
}
40
41
class Minor
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
42
{
43
    private $name;
44
45
    public function __construct($name)
46
    {
47
        $this->name = $name;
48
    }
49
50
    public function __toString()
51
    {
52
        return $this->name;
53
    }
54
}
55