JsExtractorTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A providePaths() 0 5 1
A testExtraction() 0 23 1
1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\Tests\Translator\Extractor;
4
5
use Incenteev\TranslationCheckerBundle\Translator\Extractor\JsExtractor;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Translation\MessageCatalogue;
8
9
class JsExtractorTest extends TestCase
10
{
11
    /**
12
     * @dataProvider providePaths
13
     */
14
    public function testExtraction(string $path)
15
    {
16
        $extractor = new JsExtractor(array($path), 'js');
17
        $catalogue = new MessageCatalogue('en');
18
19
        $extractor->extract($catalogue);
20
21
        $expected = array(
22
            'js' => array(
23
                'test.single_quote',
24
                'test.double_quote',
25
                'choose.single_quote',
26
                'choose.double_quote',
27
                'test.single_quote_with_spaces',
28
                'test.double_quote_with_spaces',
29
                'choose.single_quote_with_spaces',
30
                'choose.double_quote_with_spaces',
31
                'test.with_domain', // Extracting explicit domain is not supported yet. We extract them in the default domain.
32
                // dynamic_key. is not exported as it is not the full key but only the first part of a dynamically-built key
33
            )
34
        );
35
36
        $this->assertEqualsCanonicalizing($expected, $catalogue->all());// Order of translations is not relevant for the testing
37
    }
38
39
    public static function providePaths(): iterable
40
    {
41
        return array(
42
            'directory' => array(__DIR__.'/fixtures'),
43
            'file' => array(__DIR__.'/fixtures/test.js'),
44
        );
45
    }
46
}
47