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

FlushCacheTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 39
rs 10
c 1
b 0
f 0
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
    private FlushCache $sut;
15
16
    /** @var ICacheManager|MockObject */
17
    private $cacheManagerMock;
18
19
    public function setUp(): void
20
    {
21
        $this->cacheManagerMock = $this->getMockBuilder(ICacheManager::class)->getMock();
22
23
        $this->sut = new FlushCache($this->cacheManagerMock);
24
    }
25
26
    public function testExecuteFlushesCache()
27
    {
28
        $responseMock = $this->getMockBuilder(IResponse::class)
29
            ->disableOriginalConstructor()
30
            ->getMock();
31
32
        $this->cacheManagerMock->expects($this->atLeastOnce())->method('flush');
33
        $responseMock->expects($this->atLeastOnce())->method('writeln');
34
35
        $this->sut->execute($responseMock);
36
    }
37
38
    public function testExecutesWritesResponseOnExceptions()
39
    {
40
        $ex = new \RuntimeException('foo');
41
42
        $responseMock = $this->getMockBuilder(IResponse::class)
43
            ->disableOriginalConstructor()
44
            ->getMock();
45
46
        $responseMock->expects($this->atLeastOnce())->method('writeln');
47
48
        $this->cacheManagerMock->expects($this->any())->method('flush')->willThrowException($ex);
49
50
        $this->sut->execute($responseMock);
51
    }
52
}
53