|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Events\Listeners; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Events\EntityChange; |
|
8
|
|
|
use AbterPhp\Framework\Template\CacheManager; |
|
9
|
|
|
use AbterPhp\Website\Domain\Entities\Block; |
|
10
|
|
|
use AbterPhp\Website\Domain\Entities\BlockLayout; |
|
11
|
|
|
use AbterPhp\Website\Domain\Entities\Page; |
|
12
|
|
|
use AbterPhp\Website\Domain\Entities\PageCategory; |
|
13
|
|
|
use AbterPhp\Website\Domain\Entities\PageLayout; |
|
14
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class PageInvalidatorTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var PageInvalidator - System Under Test */ |
|
20
|
|
|
protected $sut; |
|
21
|
|
|
|
|
22
|
|
|
/** @var CacheManager|MockObject */ |
|
23
|
|
|
protected $cacheManagerMock; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->cacheManagerMock = $this->createMock(CacheManager::class); |
|
28
|
|
|
|
|
29
|
|
|
$this->sut = new PageInvalidator($this->cacheManagerMock); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return array |
|
34
|
|
|
*/ |
|
35
|
|
|
public function handleFlushesCacheManagerProvider(): array |
|
36
|
|
|
{ |
|
37
|
|
|
return [ |
|
38
|
|
|
[new EntityChange($this->createMock(Page::class), 'foo'), 1], |
|
39
|
|
|
[new EntityChange($this->createMock(PageLayout::class), 'foo'), 1], |
|
40
|
|
|
[new EntityChange($this->createMock(Block::class), 'foo'), 1], |
|
41
|
|
|
[new EntityChange($this->createMock(BlockLayout::class), 'foo'), 0], |
|
42
|
|
|
[new EntityChange($this->createMock(PageCategory::class), 'foo'), 0], |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @dataProvider handleFlushesCacheManagerProvider |
|
48
|
|
|
* |
|
49
|
|
|
* @param EntityChange $event |
|
50
|
|
|
* @param int $flushCount |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testHandleFlushesCacheManager(EntityChange $event, int $flushCount) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->cacheManagerMock->expects($this->exactly($flushCount))->method('flush'); |
|
55
|
|
|
|
|
56
|
|
|
$this->sut->handle($event); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|