Completed
Push — master ( 17598f...abee1f )
by Kirill
13s queued 11s
created

ConsoleDispatcherTest::testCanServe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Framework\Dispatcher;
13
14
use Spiral\Console\ConsoleDispatcher;
15
use Spiral\Tests\Framework\BaseTest;
16
use Symfony\Component\Console\Input\ArrayInput;
17
use Symfony\Component\Console\Output\BufferedOutput;
18
19
class ConsoleDispatcherTest extends BaseTest
20
{
21
    public function testCanServe(): void
22
    {
23
        $this->assertTrue($this->makeApp()->get(ConsoleDispatcher::class)->canServe());
24
    }
25
26
    public function testCanNotServe(): void
27
    {
28
        $this->assertFalse($this->makeApp([
29
            'RR' => true
30
        ])->get(ConsoleDispatcher::class)->canServe());
31
    }
32
33
    public function testListCommands(): void
34
    {
35
        $output = new BufferedOutput();
36
        $serveResult = $this->makeApp()->get(ConsoleDispatcher::class)->serve(new ArrayInput([]), $output);
37
        $result = $output->fetch();
38
39
        $this->assertStringContainsString('dead', $result);
40
        $this->assertSame(0, $serveResult);
41
    }
42
43
    public function testException(): void
44
    {
45
        $output = new BufferedOutput();
46
        $serveResult = $this->makeApp()->get(ConsoleDispatcher::class)->serve(new ArrayInput([
47
            'command' => 'dead'
48
        ]), $output);
49
        $result = $output->fetch();
50
51
        $this->assertStringContainsString('undefined', $result);
52
        $this->assertStringContainsString('DeadCommand.php', $result);
53
        $this->assertNotEquals(0, $serveResult);
54
    }
55
56
    public function testExceptionVerbose(): void
57
    {
58
        $output = new BufferedOutput();
59
        $output->setVerbosity(BufferedOutput::VERBOSITY_VERBOSE);
60
        $serveResult = $this->makeApp()->get(ConsoleDispatcher::class)->serve(new ArrayInput([
61
            'command' => 'dead'
62
        ]), $output);
63
        $result = $output->fetch();
64
65
        $this->assertStringContainsString('undefined', $result);
66
        $this->assertStringContainsString('DeadCommand.php', $result);
67
        $this->assertNotEquals(0, $serveResult);
68
    }
69
70
    public function testExceptionDebug(): void
71
    {
72
        $output = new BufferedOutput();
73
        $output->setVerbosity(BufferedOutput::VERBOSITY_DEBUG);
74
        $serveResult = $this->makeApp()->get(ConsoleDispatcher::class)->serve(new ArrayInput([
75
            'command' => 'dead'
76
        ]), $output);
77
        $result = $output->fetch();
78
79
        $this->assertStringContainsString('undefined', $result);
80
        $this->assertStringContainsString('DeadCommand.php', $result);
81
        $this->assertStringContainsString('->perform()', $result);
82
        $this->assertStringContainsString('$undefined', $result);
83
        $this->assertNotEquals(0, $serveResult);
84
    }
85
}
86