SetupTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 65
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteCallsDefaultSubCommand() 0 15 1
A setUp() 0 3 1
A testExecutesWritesResponseOnExceptions() 0 19 1
A testExecuteCallsAdditionalSubCommands() 0 17 1
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
    /** @var Setup - System Under Test */
14
    protected Setup $sut;
15
16
    public function setUp(): void
17
    {
18
        $this->sut = new Setup();
19
    }
20
21
    public function testExecuteCallsDefaultSubCommand(): void
22
    {
23
        $responseMock = $this->getMockBuilder(IResponse::class)
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
27
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
28
            ->disableOriginalConstructor()
29
            ->getMock();
30
31
        $commandCollectionMock->expects($this->once())->method('call');
32
33
        $this->sut->setCommandCollection($commandCollectionMock);
34
35
        $this->sut->execute($responseMock);
36
    }
37
38
    public function testExecuteCallsAdditionalSubCommands(): void
39
    {
40
        $responseMock = $this->getMockBuilder(IResponse::class)
41
            ->disableOriginalConstructor()
42
            ->getMock();
43
44
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
45
            ->disableOriginalConstructor()
46
            ->getMock();
47
48
        $commandCollectionMock->expects($this->exactly(2))->method('call');
49
50
        $this->sut->addSubCommand('foo');
51
52
        $this->sut->setCommandCollection($commandCollectionMock);
53
54
        $this->sut->execute($responseMock);
55
    }
56
57
    public function testExecutesWritesResponseOnExceptions(): void
58
    {
59
        $ex = new \RuntimeException('foo');
60
61
        $responseMock = $this->getMockBuilder(IResponse::class)
62
            ->disableOriginalConstructor()
63
            ->getMock();
64
65
        $responseMock->expects($this->atLeastOnce())->method('writeln');
66
67
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
68
            ->disableOriginalConstructor()
69
            ->getMock();
70
71
        $commandCollectionMock->expects($this->any())->method('call')->willThrowException($ex);
72
73
        $this->sut->setCommandCollection($commandCollectionMock);
74
75
        $this->sut->execute($responseMock);
76
    }
77
}
78