Passed
Pull Request — master (#20)
by Christophe
03:13
created

CompareCommandTest::provideCommandData()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 104
Code Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 81
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 104
rs 8.2857

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\Tests\Command;
4
5
use Incenteev\TranslationCheckerBundle\Command\CompareCommand;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Tester\CommandTester;
9
use Symfony\Component\Translation\MessageCatalogue;
10
11
class CompareCommandTest extends TestCase
12
{
13
    /**
14
     * @dataProvider provideCommandData
15
     */
16
    public function testExecute($sourceLocale, array $sourceMessages, $comparedLocale, array $comparedMessages, array $input, $expectedExitCode, $expectedMessages, $verbosity = OutputInterface::VERBOSITY_NORMAL)
17
    {
18
        $loader = $this->prophesize('Incenteev\TranslationCheckerBundle\Translator\ExposingTranslator');
19
20
        $container = $this->prophesize('Symfony\Component\DependencyInjection\ContainerInterface');
21
        $container->get('incenteev_translation_checker.exposing_translator')->willReturn($loader);
22
23
        $loader->getCatalogue($sourceLocale)->willReturn(new MessageCatalogue($sourceLocale, $sourceMessages));
24
        $loader->getCatalogue($comparedLocale)->willReturn(new MessageCatalogue($comparedLocale, $comparedMessages));
25
26
        $command = new CompareCommand();
27
        $command->setContainer($container->reveal());
28
29
        $tester = new CommandTester($command);
30
        $exitCode = $tester->execute($input, array('decorated' => false, 'verbosity' => $verbosity));
31
32
        $this->assertEquals($expectedExitCode, $exitCode);
33
34
        foreach ((array) $expectedMessages as $message) {
35
            $this->assertContains($message, $tester->getDisplay());
36
        }
37
    }
38
39
    public function provideCommandData()
40
    {
41
        return array(
42
            'sync with en' => array(
43
                'en',
44
                array('messages' => array('foo' => 'bar')),
45
                'fr',
46
                array('messages' => array('foo' => 'baz')),
47
                array('locale' => 'fr'),
48
                0,
49
                'The fr catalogue is in sync with the en one.',
50
            ),
51
            'sync with en explicit' => array(
52
                'en',
53
                array('messages' => array('foo' => 'bar'), 'test' => array('me' => 'Me')),
54
                'fr',
55
                array('messages' => array('foo' => 'baz'), 'test' => array('me' => 'Moi')),
56
                array('locale' => 'fr', 'source' => 'en'),
57
                0,
58
                'The fr catalogue is in sync with the en one.',
59
                OutputInterface::VERBOSITY_VERBOSE,
60
            ),
61
            'missing message' => array(
62
                'en',
63
                array('messages' => array('foo' => 'bar')),
64
                'fr',
65
                array('messages' => array()),
66
                array('locale' => 'fr'),
67
                1,
68
                '1 messages are missing in the messages domain',
69
            ),
70
            'missing message verbose' => array(
71
                'en',
72
                array('messages' => array('foo' => 'bar')),
73
                'fr',
74
                array('messages' => array()),
75
                array('locale' => 'fr'),
76
                1,
77
                array('1 messages are missing in the messages domain', '    foo'),
78
                OutputInterface::VERBOSITY_VERBOSE,
79
            ),
80
            'obsolete message' => array(
81
                'en',
82
                array('messages' => array('foo' => 'bar')),
83
                'fr',
84
                array('messages' => array('foo' => 'bar', 'bar' => 'baz', 'old' => 'one')),
85
                array('locale' => 'fr'),
86
                1,
87
                '2 messages are obsolete in the messages domain',
88
            ),
89
            'obsolete message verbose' => array(
90
                'en',
91
                array('messages' => array('foo' => 'bar')),
92
                'fr',
93
                array('messages' => array('foo' => 'bar', 'bar' => 'baz', 'old.key' => 'one')),
94
                array('locale' => 'fr'),
95
                1,
96
                array('2 messages are obsolete in the messages domain', '    bar', '    old.key'),
97
                OutputInterface::VERBOSITY_VERBOSE,
98
            ),
99
            'missing and obsolete message' => array(
100
                'en',
101
                array('messages' => array('foo' => 'bar'), 'test' => array('hello' => 'world')),
102
                'fr',
103
                array('messages' => array('foo' => 'bar', 'bar' => 'baz', 'old' => 'one')),
104
                array('locale' => 'fr'),
105
                1,
106
                array('2 messages are obsolete in the messages domain', '1 messages are missing in the test domain'),
107
            ),
108
            'domain restriction sync' => array(
109
                'en',
110
                array('messages' => array('foo' => 'bar'), 'test' => array('foo' => 'bar')),
111
                'fr',
112
                array('messages' => array('foo' => 'baz')),
113
                array('locale' => 'fr', '--domain' => array('messages', 'other')),
114
                0,
115
                array('The fr catalogue is in sync with the en one.', 'Checking the domains messages'),
116
            ),
117
            'domain restriction missing' => array(
118
                'en',
119
                array('messages' => array('foo' => 'bar'), 'test' => array('foo' => 'bar')),
120
                'fr',
121
                array('messages' => array('foo' => 'baz'), 'other' => array('hello' => 'world')),
122
                array('locale' => 'fr', '--domain' => array('test', 'other')),
123
                1,
124
                array('1 messages are missing in the test domain', 'Checking the domains other, test'),
125
            ),
126
            'missing and obsolete message with obsolete only' => array(
127
                'en',
128
                array('messages' => array('foo' => 'bar'), 'test' => array('hello' => 'world')),
129
                'fr',
130
                array('messages' => array('foo' => 'bar', 'bar' => 'baz', 'old' => 'one')),
131
                array('locale' => 'fr', '--obsolete-only' => true),
132
                1,
133
                array('2 messages are obsolete in the messages domain'),
134
            ),
135
            'missing message with obsolete only' => array(
136
                'en',
137
                array('messages' => array('foo' => 'bar')),
138
                'fr',
139
                array('messages' => array()),
140
                array('locale' => 'fr', '--obsolete-only' => true),
141
                0,
142
                'The fr catalogue is in sync with the en one.',
143
            ),
144
        );
145
    }
146
}
147