FlushCacheTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecutesWritesResponseOnExceptions() 0 13 1
A setUp() 0 5 1
A testExecuteFlushesCache() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Console\Commands\Assets;
6
7
use AbterPhp\Framework\Assets\CacheManager\ICacheManager;
8
use Opulence\Console\Responses\IResponse;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
12
class FlushCacheTest extends TestCase
13
{
14
    /** @var FlushCache - System Under Test */
15
    protected FlushCache $sut;
16
17
    /** @var ICacheManager|MockObject */
18
    protected $cacheManagerMock;
19
20
    public function setUp(): void
21
    {
22
        $this->cacheManagerMock = $this->getMockBuilder(ICacheManager::class)->getMock();
23
24
        $this->sut = new FlushCache($this->cacheManagerMock);
25
    }
26
27
    public function testExecuteFlushesCache(): void
28
    {
29
        $responseMock = $this->getMockBuilder(IResponse::class)
30
            ->disableOriginalConstructor()
31
            ->getMock();
32
33
        $this->cacheManagerMock->expects($this->atLeastOnce())->method('flush');
34
        $responseMock->expects($this->atLeastOnce())->method('writeln');
35
36
        $this->sut->execute($responseMock);
37
    }
38
39
    public function testExecutesWritesResponseOnExceptions(): void
40
    {
41
        $ex = new \RuntimeException('foo');
42
43
        $responseMock = $this->getMockBuilder(IResponse::class)
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
47
        $responseMock->expects($this->atLeastOnce())->method('writeln');
48
49
        $this->cacheManagerMock->expects($this->any())->method('flush')->willThrowException($ex);
50
51
        $this->sut->execute($responseMock);
52
    }
53
}
54