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->assertInternalType( 'string', $contents ); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertInternalType( 'integer', strpos( $contents, __FUNCTION__ ) ); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGivenNotFoundFile_exceptionIsThrown() { |
40
|
|
|
$fetcher = new SimpleFileFetcher(); |
41
|
|
|
|
42
|
|
|
$this->expectException( FileFetchingException::class ); |
43
|
|
|
$fetcher->fetchFile( |
44
|
|
|
'http://raw.github.com/JeroenDeDauw/FileFetcher/master/foo.php' |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGivenInvalidUrl_exceptionIsThrown() { |
49
|
|
|
$fetcher = new SimpleFileFetcher(); |
50
|
|
|
|
51
|
|
|
$this->expectException( FileFetchingException::class ); |
52
|
|
|
$fetcher->fetchFile( |
53
|
|
|
'foo bar baz' |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.