This repository was archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCacheGuardTest.php
More file actions
67 lines (54 loc) · 2.09 KB
/
CacheGuardTest.php
File metadata and controls
67 lines (54 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* @copyright 2017-present Hostnet B.V.
*/
declare(strict_types=1);
namespace Hostnet\Component\Webpack\Asset;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\LoggerInterface;
/**
* @covers \Hostnet\Component\Webpack\Asset\CacheGuard
*/
class CacheGuardTest extends TestCase
{
use ProphecyTrait;
/**
* Simple test for the case the cache is outdated.
*/
public function testCacheOutdated(): void
{
$compiler = $this->prophesize(Compiler::class);
$compiler->compile()->willReturn('some debug output');
$dumper = $this->prophesize(Dumper::class);
$dumper->dump()->shouldBeCalled();
//Cache is outdated.
$tracker = $this->prophesize(Tracker::class);
$tracker->isOutdated()->willReturn(true);
//What do we expect for logging
$logger = $this->prophesize(LoggerInterface::class);
$logger->info('[Webpack 1/2]: Compiling assets.')->shouldBeCalled();
$logger->info('[Webpack 2/2]: Dumping assets.')->shouldBeCalled();
$logger->debug('some debug output')->shouldBeCalled();
$cache_guard = new CacheGuard($compiler->reveal(), $dumper->reveal(), $tracker->reveal(), $logger->reveal());
$cache_guard->rebuild();
}
/**
* Simple test for the case the cache is not outdated.
*/
public function testCacheUpToDate(): void
{
$compiler = $this->prophesize(Compiler::class);
$compiler->compile()->willReturn('some debug output')->shouldNotBeCalled();
$dumper = $this->prophesize(Dumper::class);
$dumper->dump()->shouldNotBeCalled();
//Cache is not outdated
$tracker = $this->prophesize(Tracker::class);
$tracker->isOutdated()->willReturn(false);
//What do we expect for logging
$logger = $this->prophesize(LoggerInterface::class);
$logger->info('[Webpack]: Cache still up-to-date.')->shouldBeCalled();
$cache_guard = new CacheGuard($compiler->reveal(), $dumper->reveal(), $tracker->reveal(), $logger->reveal());
$cache_guard->rebuild();
}
}