1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\DiTesto; |
4
|
|
|
|
5
|
|
|
use LazyEight\DiTesto\Exceptions\IOException; |
6
|
|
|
use LazyEight\DiTesto\TextFile; |
7
|
|
|
use LazyEight\DiTesto\TextFileReader; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class TextFileReaderTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $file = './tests/files/urls.txt'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $imageFile = './tests/files/images.jpg'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $notReadable = './tests/files/urls_not_readable.txt'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::__construct |
29
|
|
|
* @uses \LazyEight\DiTesto\TextFileReader |
30
|
|
|
* @return \LazyEight\DiTesto\TextFileReader |
31
|
|
|
*/ |
32
|
|
|
public function testCanBeCreated() |
33
|
|
|
{ |
34
|
|
|
$filename = $this->file; |
35
|
|
|
$instance = new TextFileReader($filename); |
36
|
|
|
$this->assertInstanceOf(TextFileReader::class, $instance); |
37
|
|
|
|
38
|
|
|
return $instance; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::readFile |
43
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::valid |
44
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validatePath |
45
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validateReadable |
46
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validateType |
47
|
|
|
* @uses \LazyEight\DiTesto\TextFileReader |
48
|
|
|
* @depends testCanBeCreated |
49
|
|
|
* @uses \LazyEight\DiTesto\TextFileReader |
50
|
|
|
* @param \LazyEight\DiTesto\TextFileLoader |
51
|
|
|
*/ |
52
|
|
|
public function testCanBeLoaded(TextFileReader $loader) |
53
|
|
|
{ |
54
|
|
|
$this->assertInstanceOf(TextFile::class, $loader->readFile()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::readFile |
59
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::valid |
60
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validatePath |
61
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\IOException |
62
|
|
|
* @uses \LazyEight\DiTesto\TextFileReader |
63
|
|
|
*/ |
64
|
|
|
public function testCantBeLoaded() |
65
|
|
|
{ |
66
|
|
|
$loader = new TextFileReader(''); |
67
|
|
|
$this->expectException(IOException::class); |
68
|
|
|
$loader->readFile(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::readFile |
73
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::valid |
74
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validatePath |
75
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validateType |
76
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\IOException |
77
|
|
|
*/ |
78
|
|
|
public function testInvalidType() |
79
|
|
|
{ |
80
|
|
|
$instance = new TextFileReader($this->imageFile); |
81
|
|
|
$this->expectException(IOException::class); |
82
|
|
|
$instance->readFile(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::readFile |
87
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::valid |
88
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validatePath |
89
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::validateReadable |
90
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\IOException |
91
|
|
|
*/ |
92
|
|
|
public function testCantRead() |
93
|
|
|
{ |
94
|
|
|
chmod($this->notReadable, 0000); |
95
|
|
|
|
96
|
|
|
$instance = new TextFileReader($this->notReadable); |
97
|
|
|
$this->expectException(IOException::class); |
98
|
|
|
$instance->readFile(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::readFile |
103
|
|
|
* @covers \LazyEight\DiTesto\TextFileReader::getPath |
104
|
|
|
* @uses \LazyEight\DiTesto\TextFileReader |
105
|
|
|
*/ |
106
|
|
|
public function testCanGetPath() |
107
|
|
|
{ |
108
|
|
|
$loader = new TextFileReader($this->file); |
109
|
|
|
$this->assertEquals($this->file, $loader->getPath()); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|