Passed
Push — main ( a1448d...532f1f )
by Peter
03:51
created

SetupTest::testExecuteCallsDefaultSubCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 15
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Console\Commands\AbterPhp;
6
7
use Opulence\Console\Commands\CommandCollection;
8
use Opulence\Console\Responses\IResponse;
9
use PHPUnit\Framework\TestCase;
10
11
class SetupTest extends TestCase
12
{
13
    private Setup $sut;
14
15
    public function setUp(): void
16
    {
17
        $this->sut = new Setup();
18
    }
19
20
    public function testExecuteCallsDefaultSubCommand()
21
    {
22
        $responseMock = $this->getMockBuilder(IResponse::class)
23
            ->disableOriginalConstructor()
24
            ->getMock();
25
26
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
30
        $commandCollectionMock->expects($this->once())->method('call');
31
32
        $this->sut->setCommandCollection($commandCollectionMock);
33
34
        $this->sut->execute($responseMock);
35
    }
36
37
    public function testExecuteCallsAdditionalSubCommands()
38
    {
39
        $responseMock = $this->getMockBuilder(IResponse::class)
40
            ->disableOriginalConstructor()
41
            ->getMock();
42
43
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
47
        $commandCollectionMock->expects($this->exactly(2))->method('call');
48
49
        $this->sut->addSubCommand('foo');
50
51
        $this->sut->setCommandCollection($commandCollectionMock);
52
53
        $this->sut->execute($responseMock);
54
    }
55
56
    public function testExecutesWritesResponseOnExceptions()
57
    {
58
        $ex = new \RuntimeException('foo');
59
60
        $responseMock = $this->getMockBuilder(IResponse::class)
61
            ->disableOriginalConstructor()
62
            ->getMock();
63
64
        $responseMock->expects($this->atLeastOnce())->method('writeln');
65
66
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
67
            ->disableOriginalConstructor()
68
            ->getMock();
69
70
        $commandCollectionMock->expects($this->any())->method('call')->willThrowException($ex);
71
72
        $this->sut->setCommandCollection($commandCollectionMock);
73
74
        $this->sut->execute($responseMock);
75
    }
76
}
77