Passed
Push — main ( 4bc471...1a87b8 )
by Peter
02:53
created

FlushCacheTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testDoExecuteWritesErrorMessageOnException() 0 18 1
A testDoExecuteCallsExtraSubCommands() 0 16 1
A testDoExecuteCallsAllDefaultSubCommands() 0 14 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 FlushCacheTest extends TestCase
12
{
13
    private FlushCache $sut;
14
15
    public function setUp(): void
16
    {
17
        $this->sut = new FlushCache();
18
    }
19
20
    public function testDoExecuteCallsAllDefaultSubCommands()
21
    {
22
        $responseMock          = $this
23
            ->getMockBuilder(IResponse::class)
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
30
        $commandCollectionMock->expects($this->exactly(4))->method('call');
31
32
        $this->sut->setCommandCollection($commandCollectionMock);
33
        $this->sut->execute($responseMock);
34
    }
35
36
    public function testDoExecuteCallsExtraSubCommands()
37
    {
38
        $responseMock          = $this
39
            ->getMockBuilder(IResponse::class)
40
            ->disableOriginalConstructor()
41
            ->getMock();
42
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
43
            ->disableOriginalConstructor()
44
            ->getMock();
45
46
        $commandCollectionMock->expects($this->exactly(5))->method('call');
47
48
        $this->sut->addSubCommand('foo');
49
50
        $this->sut->setCommandCollection($commandCollectionMock);
51
        $this->sut->execute($responseMock);
52
    }
53
54
    public function testDoExecuteWritesErrorMessageOnException()
55
    {
56
        $ex = new \Exception();
57
58
        $responseMock          = $this
59
            ->getMockBuilder(IResponse::class)
60
            ->disableOriginalConstructor()
61
            ->getMock();
62
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
63
            ->disableOriginalConstructor()
64
            ->getMock();
65
66
        $responseMock->expects($this->exactly(8))->method('writeln');
67
68
        $commandCollectionMock->expects($this->exactly(4))->method('call')->willThrowException($ex);
69
70
        $this->sut->setCommandCollection($commandCollectionMock);
71
        $this->sut->execute($responseMock);
72
    }
73
}
74