Completed
Push — master ( 2ed772...f9eac7 )
by Jeroen De
03:30
created

tests/Unit/CachingFileFetcherTest.php (4 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare( strict_types=1 );
4
5
namespace FileFetcher\Tests\Unit;
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 );
0 ignored issues
show
$fileFetcher is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FileFetcher\FileFetcher>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$cache is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<SimpleCache\Cache\Cache>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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 );
0 ignored issues
show
$fileFetcher is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FileFetcher\FileFetcher>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$cache is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<SimpleCache\Cache\Cache>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
		$cachingFetcher->fetchFile( $fileUrl );
67
	}
68
69
}
70