Passed
Push — master ( 012547...6578cc )
by Christophe
07:12
created

FindMissingCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 70
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B provideCommandData() 0 39 1
A testExecute() 0 23 2
1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\Tests\Command;
4
5
use Incenteev\TranslationCheckerBundle\Command\FindMissingCommand;
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Argument;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Tester\CommandTester;
10
use Symfony\Component\Translation\MessageCatalogue;
11
12
class FindMissingCommandTest extends TestCase
13
{
14
    /**
15
     * @dataProvider provideCommandData
16
     */
17
    public function testExecute($locale, array $sourceMessages, array $extractedMessages, $expectedExitCode, $expectedMessages, $verbosity = OutputInterface::VERBOSITY_NORMAL)
18
    {
19
        $loader = $this->prophesize('Incenteev\TranslationCheckerBundle\Translator\ExposingTranslator');
20
        $extractor = $this->prophesize('Incenteev\TranslationCheckerBundle\Translator\Extractor\ExtractorInterface');
21
22
        $loader->getCatalogue($locale)->willReturn(new MessageCatalogue($locale, $sourceMessages));
23
24
        $extractor->extract(Argument::type('Symfony\Component\Translation\MessageCatalogue'))->will(function ($args) use ($extractedMessages) {
25
            /** @var MessageCatalogue $catalogue */
26
            $catalogue = $args[0];
27
28
            $catalogue->addCatalogue(new MessageCatalogue($catalogue->getLocale(), $extractedMessages));
29
        });
30
31
        $command = new FindMissingCommand($loader->reveal(), $extractor->reveal());
32
33
        $tester = new CommandTester($command);
34
        $exitCode = $tester->execute(array('locale' => $locale), array('decorated' => false, 'verbosity' => $verbosity));
35
36
        $this->assertEquals($expectedExitCode, $exitCode);
37
38
        foreach ((array) $expectedMessages as $message) {
39
            $this->assertContains($message, $tester->getDisplay());
40
        }
41
    }
42
43
    public function provideCommandData()
44
    {
45
        return array(
46
            'sync with en' => array(
47
                'en',
48
                array('messages' => array('foo' => 'bar')),
49
                array('messages' => array('foo' => 'baz')),
50
                0,
51
                'The en catalogue is in sync with the extracted one.',
52
            ),
53
            'extra messages' => array(
54
                'en',
55
                array('messages' => array('foo' => 'bar'), 'test' => array('hello' => 'world')),
56
                array('messages' => array('foo' => 'baz')),
57
                0,
58
                'The en catalogue is in sync with the extracted one.',
59
                OutputInterface::VERBOSITY_VERBOSE,
60
            ),
61
            'missing message' => array(
62
                'en',
63
                array('messages' => array('foo' => 'bar')),
64
                array('messages' => array('foo' => 'bar'), 'test' => array('hello' => 'world')),
65
                1,
66
                '1 messages are missing in the test domain',
67
            ),
68
            'missing message verbose' => array(
69
                'en',
70
                array('messages' => array('foo' => 'bar')),
71
                array('messages' => array('foo' => 'bar'), 'test' => array('hello' => 'world')),
72
                1,
73
                array('1 messages are missing in the test domain', '    hello'),
74
                OutputInterface::VERBOSITY_VERBOSE,
75
            ),
76
            'missing multiple domains' => array(
77
                'en',
78
                array('messages' => array('foo' => 'bar')),
79
                array('messages' => array('foo' => 'bar', 'bar' => 'baz'), 'test' => array('hello' => 'world', 'world' => 'wide')),
80
                1,
81
                array('1 messages are missing in the messages domain', '2 messages are missing in the test domain'),
82
            ),
83
        );
84
    }
85
}
86