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

FlushCacheTest::testExecuteFlushesCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 10
c 1
b 0
f 0
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