Completed
Push — master ( c5c436...b453a3 )
by Ruud
15:58
created

unit/Service/Importer/ImportCommandHandlerTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Tests\Service\Importer;
4
5
use Kunstmaan\TranslatorBundle\Model\Import\ImportCommand;
6
use Kunstmaan\TranslatorBundle\Tests\unit\WebTestCase;
7
use Symfony\Component\HttpKernel\Kernel;
8
9
class ImportCommandHandlerTest extends WebTestCase
10
{
11
    private $importCommandHandler;
12
13 View Code Duplication
    public function setUp()
14
    {
15
        static::bootKernel(['test_case' => 'TranslatorBundleTest', 'root_config' => 'config.yaml']);
16
        $container = static::$kernel->getContainer();
17
        static::loadFixtures($container);
18
19
        $this->importCommandHandler = $container->get('kunstmaan_translator.service.importer.command_handler');
20
    }
21
22
    /**
23
     * @group handler
24
     */
25
    public function testExecuteImportCommand()
26
    {
27
        $importCommand = new ImportCommand();
28
        $importCommand
29
            ->setForce(false)
30
            ->setLocales(false)
31
            ->setGlobals(true)
32
            ->setDefaultBundle(false);
33
34
        $this->assertEquals(7, $this->importCommandHandler->executeImportCommand($importCommand));
35
    }
36
37
    public function testdetermineLocalesToImport()
38
    {
39
        $importCommand = new ImportCommand();
40
        $importCommand
41
            ->setForce(false)
42
            ->setLocales(false)
43
            ->setGlobals(true)
44
            ->setDefaultBundle(false);
45
46
        $locales = $this->importCommandHandler->determineLocalesToImport($importCommand);
47
        $this->assertEquals(array('nl', 'en', 'de'), $locales);
48
    }
49
50
    public function testParseRequestedLocalesMulti()
51
    {
52
        $locale = 'nl,De,   FR';
53
        $expectedArray = array('nl', 'de', 'fr');
54
        $locales = $this->importCommandHandler->parseRequestedLocales($locale);
55
        $this->assertEquals($expectedArray, $locales);
56
    }
57
58
    public function testParseRequestedLocalesSingle()
59
    {
60
        $locale = 'dE';
61
        $expectedArray = array('de');
62
        $locales = $this->importCommandHandler->parseRequestedLocales($locale);
63
        $this->assertEquals($expectedArray, $locales);
64
    }
65
66
    public function testParseRequestedLocalesArray()
67
    {
68
        $locale = array('dE', 'NL', 'es');
69
        $expectedArray = array('de', 'nl', 'es');
70
        $locales = $this->importCommandHandler->parseRequestedLocales($locale);
71
        $this->assertEquals($expectedArray, $locales);
72
    }
73
74
    /**
75
     * @group legacy
76
     */
77 View Code Duplication
    public function testImportBundleTranslationFiles()
78
    {
79
        if (Kernel::VERSION_ID >= 40000) {
80
            $this->markTestSkipped('Skip symfony 3 test');
81
        }
82
83
        $importCommand = new ImportCommand();
84
        $importCommand
85
            ->setForce(false)
86
            ->setLocales(false)
87
            ->setGlobals(true)
88
            ->setDefaultBundle('own');
89
90
        $this->assertEquals(0, $this->importCommandHandler->importBundleTranslationFiles($importCommand));
91
    }
92
93 View Code Duplication
    public function testImportSf4TranslationFiles()
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
94
    {
95
        if (Kernel::VERSION_ID < 40000) {
96
            $this->markTestSkipped('Skip symfony 4 test');
97
        }
98
99
        $importCommand = new ImportCommand();
100
        $importCommand
101
            ->setForce(false)
102
            ->setLocales(false)
103
            ->setGlobals(true)
104
            ->setDefaultBundle('own');
105
106
        $this->assertEquals(7, $this->importCommandHandler->importBundleTranslationFiles($importCommand));
107
    }
108
}
109