Completed
Push — SpyingFileFetcher ( 3875da )
by Jeroen De
04:40
created

testWhenSomeCalls_getFetchedUrlsReturnsTheArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace FileFetcher\Tests\Phpunit;
4
5
use FileFetcher\FileFetchingException;
6
use FileFetcher\InMemoryFileFetcher;
7
use FileFetcher\SpyingFileFetcher;
8
9
/**
10
 * @covers FileFetcher\SpyingFileFetcher
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class SpyingFileFetcherTest extends \PHPUnit_Framework_TestCase {
16
17
	public function testReturnsResultOfDecoratedFetcher() {
18
		$innerFetcher = new InMemoryFileFetcher( [
19
			'url' => 'content'
20
		] );
21
22
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
23
24
		$this->assertSame( 'content', $spyingFetcher->fetchFile( 'url' ) );
25
26
		$this->expectException( FileFetchingException::class );
27
		$spyingFetcher->fetchFile( 'foo' );
28
	}
29
30
	public function testWhenNoCalls_getFetchedUrlsReturnsEmptyArray() {
31
		$innerFetcher = new InMemoryFileFetcher( [
32
			'url' => 'content'
33
		] );
34
35
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
36
37
		$this->assertSame( [], $spyingFetcher->getFetchedUrls() );
38
	}
39
40
	public function testWhenSomeCalls_getFetchedUrlsReturnsTheArguments() {
41
		$innerFetcher = new InMemoryFileFetcher( [
42
			'url' => 'content',
43
			'foo' => 'bar'
44
		] );
45
46
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
47
		$spyingFetcher->fetchFile( 'url' );
48
		$spyingFetcher->fetchFile( 'foo' );
49
		$spyingFetcher->fetchFile( 'url' );
50
51
		$this->assertSame( [ 'url', 'foo', 'url' ], $spyingFetcher->getFetchedUrls() );
52
	}
53
54
	public function testCallsCausingExceptionsGetRecorded() {
55
		$innerFetcher = new InMemoryFileFetcher( [] );
56
57
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
58
59
		try {
60
			$spyingFetcher->fetchFile( 'url' );
61
		}
62
		catch ( FileFetchingException $ex ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
63
		}
64
65
		try {
66
			$spyingFetcher->fetchFile( 'foo' );
67
		}
68
		catch ( FileFetchingException $ex ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
69
		}
70
71
		$this->assertSame( [ 'url', 'foo' ], $spyingFetcher->getFetchedUrls() );
72
	}
73
74
}
75