|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace FileFetcher\Tests\Integration; |
|
6
|
|
|
|
|
7
|
|
|
use FileFetcher\FileFetchingException; |
|
8
|
|
|
use FileFetcher\SimpleFileFetcher; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \FileFetcher\SimpleFileFetcher |
|
13
|
|
|
* |
|
14
|
|
|
* @licence BSD-3-Clause |
|
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
16
|
|
|
*/ |
|
17
|
|
|
class SimpleFileFetcherTest extends TestCase { |
|
18
|
|
|
|
|
19
|
|
|
public function testGetThisFileFromDisk() { |
|
20
|
|
|
$fetcher = new SimpleFileFetcher(); |
|
21
|
|
|
|
|
22
|
|
|
$contents = $fetcher->fetchFile( __FILE__ ); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertSame( file_get_contents( __FILE__ ), $contents ); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetThisFileFromGitHub() { |
|
28
|
|
|
$fetcher = new SimpleFileFetcher(); |
|
29
|
|
|
|
|
30
|
|
|
$contents = $fetcher->fetchFile( |
|
31
|
|
|
'https://raw.githubusercontent.com/JeroenDeDauw/FileFetcher/master/tests/Integration/SimpleFileFetcherTest.php' |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertIsString( $contents ); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertContains( __FUNCTION__, $contents ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGivenNotFoundFile_exceptionIsThrown() { |
|
40
|
|
|
$fetcher = new SimpleFileFetcher(); |
|
41
|
|
|
$invalidRemoteFileUrl = 'http://raw.github.com/JeroenDeDauw/FileFetcher/master/foo.php'; |
|
42
|
|
|
|
|
43
|
|
|
$this->expectException( FileFetchingException::class ); |
|
44
|
|
|
$this->expectExceptionMessage( 'Could not fetch file: ' . $invalidRemoteFileUrl ); |
|
45
|
|
|
$fetcher->fetchFile( $invalidRemoteFileUrl ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testGivenInvalidUrl_exceptionIsThrown() { |
|
49
|
|
|
$fetcher = new SimpleFileFetcher(); |
|
50
|
|
|
$invalidRemoteFileUrl = 'foo bar baz'; |
|
51
|
|
|
|
|
52
|
|
|
$this->expectException( FileFetchingException::class ); |
|
53
|
|
|
$this->expectExceptionMessage( 'Could not fetch file: ' . $invalidRemoteFileUrl ); |
|
54
|
|
|
$fetcher->fetchFile( $invalidRemoteFileUrl ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|