Passed
Push — master ( d2e487...b38026 )
by Tobias
05:31
created

StatusCommandTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 34
rs 9.52
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\Tests\Functional\Command;
13
14
use Symfony\Bundle\FrameworkBundle\Console\Application;
15
use Symfony\Component\Console\Tester\CommandTester;
16
use Translation\Bundle\Command\StatusCommand;
17
use Translation\Bundle\Tests\Functional\BaseTestCase;
18
19
class StatusCommandTest extends BaseTestCase
20
{
21
    protected function setUp(): void
22
    {
23
        parent::setUp();
24
        $this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yaml');
25
    }
26
27
    public function testExecute(): void
28
    {
29
        $this->bootKernel();
30
        $application = new Application($this->kernel);
31
32
        $container = $this->getContainer();
33
        $application->add($container->get(StatusCommand::class));
0 ignored issues
show
Bug introduced by
It seems like $container->get(Translat...d\StatusCommand::class) can also be of type null; however, parameter $command of Symfony\Bundle\Framework...sole\Application::add() does only seem to accept Symfony\Component\Console\Command\Command, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        $application->add(/** @scrutinizer ignore-type */ $container->get(StatusCommand::class));
Loading history...
34
35
        $command = $application->find('translation:status');
36
        $commandTester = new CommandTester($command);
37
        $commandTester->execute([
38
            'command' => $command->getName(),
39
            'configuration' => 'app',
40
            'locale' => 'en',
41
            '--json' => true,
42
        ]);
43
44
        // the output of the command in the console
45
        $output = $commandTester->getDisplay();
46
        $data = \json_decode($output, true);
47
48
        $this->assertArrayHasKey('en', $data);
49
        $this->assertArrayHasKey('messages', $data['en']);
50
        $this->assertArrayHasKey('_total', $data['en']);
51
52
        $total = $data['en']['_total'];
53
        $this->assertArrayHasKey('defined', $total);
54
        $this->assertArrayHasKey('new', $total);
55
        $this->assertArrayHasKey('obsolete', $total);
56
        $this->assertArrayHasKey('approved', $total);
57
        $this->assertEquals(2, $total['defined']);
58
        $this->assertEquals(1, $total['new']);
59
        $this->assertEquals(0, $total['obsolete']);
60
        $this->assertEquals(1, $total['approved']);
61
    }
62
}
63