CallbackFileFetcherTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCallbackGetsFileUrlAndReturnValueIsReturned() 0 7 1
A testCallbackExceptionBubblesUp() 0 10 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace FileFetcher\Tests\Unit;
6
7
use FileFetcher\CallbackFileFetcher;
8
use FileFetcher\FileFetchingException;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \FileFetcher\CallbackFileFetcher
13
 *
14
 * @licence BSD-3-Clause
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class CallbackFileFetcherTest extends TestCase {
18
19
	public function testCallbackGetsFileUrlAndReturnValueIsReturned() {
20
		$fetcher = new CallbackFileFetcher( function( string $fileUrl ) {
21
			return $fileUrl . $fileUrl . $fileUrl;
22
		} );
23
24
		$this->assertSame( 'SuchSuchSuch', $fetcher->fetchFile( 'Such' ) );
25
	}
26
27
	public function testCallbackExceptionBubblesUp() {
28
		$fetcher = new CallbackFileFetcher( function( string $fileUrl ) {
29
			throw new FileFetchingException( $fileUrl );
30
		} );
31
		$invalidFileUrl = 'Such';
32
33
		$this->expectException( FileFetchingException::class );
34
		$this->expectExceptionMessage( 'Could not fetch file: ' . $invalidFileUrl );
35
		$fetcher->fetchFile( $invalidFileUrl );
36
	}
37
38
}
39