1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\DiTesto\FileSystem; |
4
|
|
|
|
5
|
|
|
use LazyEight\DiTesto\FileSystem\FileSystemHandler; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class FileSystemHandlerTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $path = './tests/files'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $files = ['urls.txt', 'images.jpg', 'urls_not_readable.txt']; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $sizes = [121, 8402, 121]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $types = ['text/plain', 'image/jpeg', 'text/plain']; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $file = './tests/files/urls.txt'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $imageFile = './tests/files/images.jpg'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $notReadable = './tests/files/urls_not_readable.txt'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $notExistsFile = './tests/files/newFilename.txt'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::__construct |
52
|
|
|
* @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
53
|
|
|
*/ |
54
|
|
|
public function testCanCreate() |
55
|
|
|
{ |
56
|
|
|
$instance = new FileSystemHandler($this->file); |
57
|
|
|
$this->assertInstanceOf(FileSystemHandler::class, $instance); |
58
|
|
|
|
59
|
|
|
return $instance; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// /** |
63
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::__construct |
64
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::exists |
65
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
66
|
|
|
// */ |
67
|
|
|
// public function testExists() |
68
|
|
|
// { |
69
|
|
|
//// $this->assertTrue((new FileSystemHandler($this->file))->exists()); |
70
|
|
|
// } |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::__construct |
74
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::exists |
75
|
|
|
* @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
76
|
|
|
*/ |
77
|
|
|
// public function testNotExists() |
78
|
|
|
// { |
79
|
|
|
//// $this->assertFalse((new FileSystemHandler($this->notExistsFile))->exists()); |
80
|
|
|
// } |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::readable |
84
|
|
|
* @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
85
|
|
|
*/ |
86
|
|
|
public function testReadable() |
87
|
|
|
{ |
88
|
|
|
$this->assertTrue((new FileSystemHandler($this->file))->readable()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::readable |
93
|
|
|
* @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
94
|
|
|
*/ |
95
|
|
|
public function testNotReadable() |
96
|
|
|
{ |
97
|
|
|
$this->assertFalse((new FileSystemHandler($this->notReadable))->readable()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::writable |
102
|
|
|
* @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
103
|
|
|
*/ |
104
|
|
|
public function testWritable() |
105
|
|
|
{ |
106
|
|
|
$this->assertTrue((new FileSystemHandler($this->file))->writable()); |
107
|
|
|
$this->assertTrue((new FileSystemHandler($this->path))->writable()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::writable |
112
|
|
|
* @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
113
|
|
|
*/ |
114
|
|
|
public function testNotWritable() |
115
|
|
|
{ |
116
|
|
|
$this->assertFalse((new FileSystemHandler($this->notReadable))->writable()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// /** |
120
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::pathName |
121
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
122
|
|
|
// */ |
123
|
|
|
// public function testGetPathName() |
124
|
|
|
// { |
125
|
|
|
//// $this->assertEquals($this->path, (new FileSystemHandler($this->file))->pathName()); |
126
|
|
|
//// $this->assertEquals($this->path, (new FileSystemHandler($this->imageFile))->pathName()); |
127
|
|
|
//// $this->assertEquals($this->path, (new FileSystemHandler($this->notReadable))->pathName()); |
128
|
|
|
// } |
129
|
|
|
// |
130
|
|
|
// /** |
131
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::pathName |
132
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
133
|
|
|
// */ |
134
|
|
|
// public function testCantGetPathName() |
135
|
|
|
// { |
136
|
|
|
//// $this->assertNotEquals('', (new FileSystemHandler($this->file))->pathName()); |
137
|
|
|
//// $this->assertNotEquals($this->file, (new FileSystemHandler($this->file))->pathName()); |
138
|
|
|
//// $this->assertNotEquals($this->imageFile, (new FileSystemHandler($this->file))->pathName()); |
139
|
|
|
// } |
140
|
|
|
// |
141
|
|
|
// /** |
142
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::filename |
143
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
144
|
|
|
// */ |
145
|
|
|
// public function testGetFileName() |
146
|
|
|
// { |
147
|
|
|
//// $this->assertEquals($this->files[0], (new FileSystemHandler($this->file))->filename()); |
148
|
|
|
//// $this->assertEquals($this->files[1], (new FileSystemHandler($this->imageFile))->filename()); |
149
|
|
|
//// $this->assertEquals($this->files[2], (new FileSystemHandler($this->notReadable))->filename()); |
150
|
|
|
// } |
151
|
|
|
// |
152
|
|
|
// /** |
153
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::filename |
154
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
155
|
|
|
// */ |
156
|
|
|
// public function testCantGetFileName() |
157
|
|
|
// { |
158
|
|
|
//// $this->assertNotEquals($this->file, (new FileSystemHandler($this->file))->filename()); |
159
|
|
|
//// $this->assertNotEquals('', (new FileSystemHandler($this->file))->filename()); |
160
|
|
|
//// $this->assertNotEquals($this->file, (new FileSystemHandler($this->imageFile))->filename()); |
161
|
|
|
//// $this->assertNotEquals('', (new FileSystemHandler($this->imageFile))->filename()); |
162
|
|
|
// } |
163
|
|
|
// |
164
|
|
|
// /** |
165
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::size |
166
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
167
|
|
|
// */ |
168
|
|
|
// public function testGetSize() |
169
|
|
|
// { |
170
|
|
|
//// $this->assertEquals($this->sizes[0], (new FileSystemHandler($this->file))->size()); |
171
|
|
|
//// $this->assertEquals($this->sizes[1], (new FileSystemHandler($this->imageFile))->size()); |
172
|
|
|
//// $this->assertEquals($this->sizes[2], (new FileSystemHandler($this->notReadable))->size()); |
173
|
|
|
// } |
174
|
|
|
// |
175
|
|
|
// /** |
176
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::filename |
177
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
178
|
|
|
// */ |
179
|
|
|
// public function testCantGetSize() |
180
|
|
|
// { |
181
|
|
|
//// $this->assertNotEquals($this->sizes[1], (new FileSystemHandler($this->file))->size()); |
182
|
|
|
//// $this->assertNotEquals($this->sizes[0], (new FileSystemHandler($this->imageFile))->size()); |
183
|
|
|
// } |
184
|
|
|
// |
185
|
|
|
// /** |
186
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::type |
187
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
188
|
|
|
// */ |
189
|
|
|
// public function testGetType() |
190
|
|
|
// { |
191
|
|
|
//// $this->assertEquals($this->types[0], (new FileSystemHandler($this->file))->type()); |
192
|
|
|
//// $this->assertEquals($this->types[1], (new FileSystemHandler($this->imageFile))->type()); |
193
|
|
|
// } |
194
|
|
|
// |
195
|
|
|
// /** |
196
|
|
|
// * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::filename |
197
|
|
|
// * @uses \LazyEight\DiTesto\FileSystem\FileSystemHandler |
198
|
|
|
// */ |
199
|
|
|
// public function testCantGetType() |
200
|
|
|
// { |
201
|
|
|
//// $this->assertNotEquals($this->types[1], (new FileSystemHandler($this->file))->type()); |
202
|
|
|
//// $this->assertNotEquals($this->types[0], (new FileSystemHandler($this->imageFile))->type()); |
203
|
|
|
// } |
204
|
|
|
} |
205
|
|
|
|