Passed
Push — master ( 3dccfd...4f0ddc )
by Jeroen De
42s
created

testWhenThereIsADefault_itIsNotUsedForKnownUrls()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
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\FileFetchingException;
8
use FileFetcher\InMemoryFileFetcher;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers FileFetcher\InMemoryFileFetcher
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class InMemoryFileFetcherTest extends TestCase {
18
19
	public function testWhenEmptyHash_requestsCauseException() {
20
		$fetcher = new InMemoryFileFetcher( [] );
21
22
		$this->expectException( FileFetchingException::class );
23
		$fetcher->fetchFile( 'http://foo.bar/baz' );
24
	}
25
26
	public function testWhenUrlNotKnown_requestsCauseException() {
27
		$fetcher = new InMemoryFileFetcher( [
28
			'http://something.else/entirely' => 'kittens'
29
		] );
30
31
		$this->expectException( FileFetchingException::class );
32
		$fetcher->fetchFile( 'http://foo.bar/baz' );
33
	}
34
35
	public function testWhenUrlKnown_requestsReturnsValue() {
36
		$fetcher = new InMemoryFileFetcher( [
37
			'http://something.else/entirely' => 'kittens',
38
			'http://foo.bar/baz' => 'cats'
39
		] );
40
41
		$this->assertSame( 'cats', $fetcher->fetchFile( 'http://foo.bar/baz' ) );
42
	}
43
44
	public function testWhenThereIsADefault_itIsUsedForUnknownUrls() {
45
		$fetcher = new InMemoryFileFetcher( [], 'default kittens' );
46
47
		$this->assertSame( 'default kittens', $fetcher->fetchFile( 'http://foo.bar' ) );
48
	}
49
50
	public function testWhenThereIsADefault_itIsNotUsedForKnownUrls() {
51
		$fetcher = new InMemoryFileFetcher(
52
			[
53
				'http://foo.bar' => 'cats'
54
			],
55
			'default kittens'
56
		);
57
58
		$this->assertSame( 'cats', $fetcher->fetchFile( 'http://foo.bar' ) );
59
	}
60
61
}
62