Passed
Push — master ( 792f58...5e1240 )
by Jeroen De
37s
created

SpyingFileFetcherTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testReturnsResultOfDecoratedFetcher() 0 12 1
A testWhenNoCalls_getFetchedUrlsReturnsEmptyArray() 0 9 1
A testWhenSomeCalls_getFetchedUrlsReturnsTheArguments() 0 13 1
A testCallsCausingExceptionsGetRecorded() 0 21 3
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 FileFetcher\SpyingFileFetcher;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * @covers FileFetcher\SpyingFileFetcher
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class SpyingFileFetcherTest extends TestCase {
19
20
	public function testReturnsResultOfDecoratedFetcher() {
21
		$innerFetcher = new InMemoryFileFetcher( [
22
			'url' => 'content'
23
		] );
24
25
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
26
27
		$this->assertSame( 'content', $spyingFetcher->fetchFile( 'url' ) );
28
29
		$this->expectException( FileFetchingException::class );
30
		$spyingFetcher->fetchFile( 'foo' );
31
	}
32
33
	public function testWhenNoCalls_getFetchedUrlsReturnsEmptyArray() {
34
		$innerFetcher = new InMemoryFileFetcher( [
35
			'url' => 'content'
36
		] );
37
38
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
39
40
		$this->assertSame( [], $spyingFetcher->getFetchedUrls() );
41
	}
42
43
	public function testWhenSomeCalls_getFetchedUrlsReturnsTheArguments() {
44
		$innerFetcher = new InMemoryFileFetcher( [
45
			'url' => 'content',
46
			'foo' => 'bar'
47
		] );
48
49
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
50
		$spyingFetcher->fetchFile( 'url' );
51
		$spyingFetcher->fetchFile( 'foo' );
52
		$spyingFetcher->fetchFile( 'url' );
53
54
		$this->assertSame( [ 'url', 'foo', 'url' ], $spyingFetcher->getFetchedUrls() );
55
	}
56
57
	public function testCallsCausingExceptionsGetRecorded() {
58
		$innerFetcher = new InMemoryFileFetcher( [] );
59
60
		$spyingFetcher = new SpyingFileFetcher( $innerFetcher );
61
62
		// @codingStandardsIgnoreStart
63
		try {
64
			$spyingFetcher->fetchFile( 'url' );
65
		}
66
		catch ( FileFetchingException $ex ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
67
		}
68
69
		try {
70
			$spyingFetcher->fetchFile( 'foo' );
71
		}
72
		catch ( FileFetchingException $ex ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
73
		}
74
		// @codingStandardsIgnoreEnd
75
76
		$this->assertSame( [ 'url', 'foo' ], $spyingFetcher->getFetchedUrls() );
77
	}
78
79
}
80