Completed
Push — php7 ( 52fd67 )
by Jeroen De
04:02
created

CachingFileFetcherTest::testCanConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
declare( strict_types=1 );
4
5
namespace FileFetcher\Tests\Phpunit;
6
7
use FileFetcher\CachingFileFetcher;
8
use FileFetcher\FileFetcher;
9
use PHPUnit\Framework\TestCase;
10
use SimpleCache\Cache\Cache;
11
12
/**
13
 * @covers FileFetcher\CachingFileFetcher
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class CachingFileFetcherTest extends TestCase {
19
20
	public function testGetFileWhenNotCached() {
21
		$fileUrl = 'foo://bar';
22
		$fileContents = 'NyanData across the sky!';
23
24
		$fileFetcher = $this->createMock( FileFetcher::class );
25
26
		$fileFetcher->expects( $this->once() )
27
			->method( 'fetchFile' )
28
			->with( $fileUrl )
29
			->will( $this->returnValue( $fileContents ) );
30
31
		$cache = $this->createMock( Cache::class );
32
33
		$cache->expects( $this->once() )
34
			->method( 'get' )
35
			->with( $fileUrl )
36
			->will( $this->returnValue( null ) );
37
38
		$cache->expects( $this->once() )
39
			->method( 'set' )
40
			->with( $fileUrl );
41
42
		$cachingFetcher = new CachingFileFetcher( $fileFetcher, $cache );
43
		$cachingFetcher->fetchFile( $fileUrl );
44
	}
45
46
	public function testGetFileWhenCached() {
47
		$fileUrl = 'foo://bar';
48
		$fileContents = 'NyanData across the sky!';
49
50
		$fileFetcher = $this->createMock( FileFetcher::class );
51
52
		$fileFetcher->expects( $this->never() )
53
			->method( 'fetchFile' );
54
55
		$cache = $this->createMock( Cache::class );
56
57
		$cache->expects( $this->once() )
58
			->method( 'get' )
59
			->with( $fileUrl )
60
			->will( $this->returnValue( $fileContents ) );
61
62
		$cache->expects( $this->never() )
63
			->method( 'set' );
64
65
		$cachingFetcher = new CachingFileFetcher( $fileFetcher, $cache );
66
		$cachingFetcher->fetchFile( $fileUrl );
67
	}
68
69
}
70