TranslationCommandTest::testExportSpecificDomain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Itkg\TranslationBundle;
4
5
use Itkg\TranslationBundle\Command\TranslationConverterCommand;
6
use Symfony\Bundle\FrameworkBundle\Console\Application;
7
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
8
use Symfony\Component\Console\Tester\CommandTester;
9
10
/**
11
 * Class TranslationCommandTest
12
 */
13
class TranslationCommandTest extends WebTestCase
14
{
15
    private $command;
16
    private $commandTester;
17
    private $exportPath;
18
    private $importPath;
19
20
    protected function setUp()
21
    {
22
        $this->exportPath = __DIR__.'/../../export';
23
        $this->importPath =  __DIR__.'/../fixtures';
24
25
        static::$kernel = static::createKernel();
26
        static::$kernel->boot();
27
28
        $extractor = static::$kernel->getContainer()->get('itkg_translation.extractor.translation');
29
        $extractor->setContainer(static::$kernel->getContainer());
30
        $writer = static::$kernel->getContainer()->get('itkg_translation.writer.message_catalogue');
31
        $writer->setContainer(static::$kernel->getContainer());
32
        $this->command     = new TranslationConverterCommand(
33
            $extractor,
34
            $writer
35
        );
36
        $application = new Application(static::$kernel);
37
        $this->command->setApplication($application);
38
        $this->commandTester = new CommandTester($this->command);
39
    }
40
41 View Code Duplication
    public function testExport()
0 ignored issues
show
Duplication introduced by
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...
42
    {
43
        $this->commandTester->execute(array(
44
            'command' => 'itkg_translation:translation:converter',
45
            '--input' => 'yml',
46
            '--output' => 'csv',
47
            '--path' => $this->importPath.'/data',
48
            '--output-path' => $this->exportPath
49
        ));
50
51
        $this->assertEquals(file_get_contents($this->exportPath.'/domain.en.csv'), file_get_contents($this->importPath.'/result/domain.en.csv'));
52
        $this->assertEquals(file_get_contents($this->exportPath.'/messages.fr.csv'), file_get_contents($this->importPath.'/result/messages.fr.csv'));
53
    }
54
55
    public function testExportSpecificDomain()
56
    {
57
        $this->commandTester->execute(array(
58
            'command'  => 'itkg_translation:translation:converter',
59
            '--input'  => 'yml',
60
            '--output' => 'csv',
61
            '--domain' => 'domain',
62
            '--path'   => $this->importPath.'/data',
63
            '--output-path' => $this->exportPath.'/domain'
64
        ));
65
66
        $this->assertCount(1, glob($this->exportPath.'/domain'));
67
        $this->assertEquals(file_get_contents($this->exportPath.'/domain/domain.en.csv'), file_get_contents($this->importPath.'/result/domain.en.csv'));
68
    }
69
70 View Code Duplication
    public function testImport()
0 ignored issues
show
Duplication introduced by
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...
71
    {
72
        $this->commandTester->execute(array(
73
            'command' => 'itkg_translation:translation:converter',
74
            '--input' => 'csv',
75
            '--output' => 'yml',
76
            '--path' => $this->importPath.'/data',
77
            '--output-path' => $this->exportPath
78
        ));
79
80
        $this->assertEquals(file_get_contents($this->exportPath.'/domain.en.yml'), file_get_contents($this->importPath.'/result/domain.en.yml'));
81
        $this->assertEquals(file_get_contents($this->exportPath.'/messages.fr.yml'), file_get_contents($this->importPath.'/result/messages.fr.yml'));
82
    }
83
}
84