|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Test\DiTesto; |
|
4
|
|
|
|
|
5
|
|
|
use LazyEight\DiTesto\Exceptions\IOException; |
|
6
|
|
|
use LazyEight\DiTesto\FileSystem\FileSystemHandler; |
|
7
|
|
|
use LazyEight\DiTesto\TextFile; |
|
8
|
|
|
use LazyEight\DiTesto\FileReader; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class FileReaderTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $file = './tests/files/urls.txt'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $imageFile = './tests/files/images.jpg'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $notReadable = './tests/files/urls_not_readable.txt'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @covers \LazyEight\DiTesto\FileReader::readFile |
|
30
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::isReadable |
|
31
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::read |
|
32
|
|
|
* @uses \LazyEight\DiTesto\FileReader |
|
33
|
|
|
* @uses \LazyEight\DiTesto\FileReader |
|
34
|
|
|
* @param \LazyEight\DiTesto\TextFileLoader |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testCanRead() |
|
37
|
|
|
{ |
|
38
|
|
|
$textFile = new TextFile($this->file); |
|
39
|
|
|
(new FileReader())->readFile($textFile, new FileSystemHandler()); |
|
40
|
|
|
|
|
41
|
|
|
$arrFile = explode(PHP_EOL, file_get_contents($this->file)); |
|
42
|
|
|
$this->assertTrue(count($arrFile) === count($textFile)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @covers \LazyEight\DiTesto\FileReader::readFile |
|
47
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::isReadable |
|
48
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::read |
|
49
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\IOException |
|
50
|
|
|
* @uses \LazyEight\DiTesto\FileReader |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testCantBeLoaded() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->expectException(IOException::class); |
|
55
|
|
|
(new FileReader())->readFile(new TextFile(''), new FileSystemHandler()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @covers \LazyEight\DiTesto\FileReader::readFile |
|
60
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\IOException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testCantRead() |
|
63
|
|
|
{ |
|
64
|
|
|
chmod($this->notReadable, 0000); |
|
65
|
|
|
|
|
66
|
|
|
$this->expectException(IOException::class); |
|
67
|
|
|
(new FileReader())->readFile(new TextFile($this->notReadable), new FileSystemHandler()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|