|
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
|
|
|
|