1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mero\Bundle\BaseBundle\Tests\Twig; |
4
|
|
|
|
5
|
|
|
use Mero\Bundle\BaseBundle\Twig\LanguageExtension; |
6
|
|
|
|
7
|
|
View Code Duplication |
class LanguageExtensionTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var LanguageExtension |
11
|
|
|
*/ |
12
|
|
|
protected $extension; |
13
|
|
|
|
14
|
|
|
protected function setUp() |
15
|
|
|
{ |
16
|
|
|
$this->extension = new LanguageExtension(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public static function dataProvider() |
20
|
|
|
{ |
21
|
|
|
return [ |
22
|
|
|
['en', 'pt_BR', 'inglês'], |
23
|
|
|
['en', 'en_US', 'English'], |
24
|
|
|
['en_US', 'pt_BR', 'inglês americano'], |
25
|
|
|
['en_US', 'en_US', 'American English'], |
26
|
|
|
['es', 'pt_BR', 'espanhol'], |
27
|
|
|
['es', 'en_US', 'Spanish'], |
28
|
|
|
['es_ES', 'pt_BR', 'espanhol europeu'], |
29
|
|
|
['es_ES', 'en_US', 'European Spanish'], |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testEmptyLanguageIso() |
34
|
|
|
{ |
35
|
|
|
$output = $this->extension->getLanguageName(null, 'pt_BR'); |
36
|
|
|
$this->assertEmpty($output); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider dataProvider |
41
|
|
|
*/ |
42
|
|
|
public function testGetLanguageName($languageIso, $locale, $expected) |
43
|
|
|
{ |
44
|
|
|
$output = $this->extension->getLanguageName($languageIso, $locale); |
45
|
|
|
$this->assertEquals($expected, $output); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.