ConsoleHelperTest::testFormatCommandHelp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 11
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
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 WBW\Bundle\CoreBundle\Tests\Console;
13
14
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Style\StyleInterface;
18
use WBW\Bundle\CoreBundle\Console\ConsoleHelper;
19
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
20
21
/**
22
 * Console helper test.
23
 *
24
 * @author webeweb <https://github.com/webeweb>
25
 * @package WBW\Bundle\CoreBundle\Tests\Console
26
 */
27
class ConsoleHelperTest extends AbstractTestCase {
28
29
    /**
30
     * Test formatCommandHelp()
31
     *
32
     * @return void
33
     */
34
    public function testFormatCommandHelp(): void {
35
36
        $exp = <<< EOT
37
The <info>%command.name%</info> command content.
38
39
    <info>php %command.full_name%</info>
40
41
42
EOT;
43
44
        $this->assertEquals($exp, ConsoleHelper::formatCommandHelp("content"));
45
    }
46
47
    /**
48
     * Test getCheckbox()
49
     *
50
     * @return void
51
     */
52
    public function testGetCheckbox(): void {
53
54
        // Determines the operating system.
55
        if ("\\" !== DIRECTORY_SEPARATOR) {
56
57
            $this->assertEquals("<fg=green;options=bold>\xE2\x9C\x94</>", ConsoleHelper::getCheckbox(true));
58
            $this->assertEquals("<fg=yellow;options=bold>!</>", ConsoleHelper::getCheckbox(false));
59
            $this->assertEquals("<fg=yellow;options=bold>!</>", ConsoleHelper::getCheckbox(null));
60
        } else {
61
62
            $this->assertEquals("<fg=green;options=bold>OK</>", ConsoleHelper::getCheckbox(true));
63
            $this->assertEquals("<fg=yellow;options=bold>WARNING</>", ConsoleHelper::getCheckbox(false));
64
            $this->assertEquals("<fg=yellow;options=bold>WARNING</>", ConsoleHelper::getCheckbox(null));
65
        }
66
    }
67
68
    /**
69
     * Test newSymfonyStyle()
70
     *
71
     * @return void
72
     */
73
    public function testNewSymfonyStyle(): void {
74
75
        // Set an Output formatter mock.
76
        $outputFormatter = $this->getMockBuilder(OutputFormatterInterface::class)->getMock();
77
78
        // Set an Input mock.
79
        $input = $this->getMockBuilder(InputInterface::class)->getMock();
80
81
        // Set an Output mock.
82
        $output = $this->getMockBuilder(OutputInterface::class)->getMock();
83
        $output->expects($this->any())->method("getFormatter")->willReturn($outputFormatter);
84
85
        $res = ConsoleHelper::newSymfonyStyle($input, $output);
86
        $this->assertInstanceOf(StyleInterface::class, $res);
87
    }
88
}
89