testCallbackExceptionBubblesUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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