1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\DiTesto\FileSystem; |
4
|
|
|
|
5
|
|
|
use LazyEight\DiTesto\FileSystem\FileSystemPath; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class FileSystemPathTest 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\FileSystemPath::__construct |
52
|
|
|
* @return FileSystemPath |
53
|
|
|
*/ |
54
|
|
|
public function testCanBeCreated() |
55
|
|
|
{ |
56
|
|
|
$instance = new FileSystemPath($this->file); |
57
|
|
|
$this->assertInstanceOf(FileSystemPath::class, $instance); |
58
|
|
|
|
59
|
|
|
return $instance; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::__construct |
64
|
|
|
*/ |
65
|
|
|
public function testCantBeCreated() |
66
|
|
|
{ |
67
|
|
|
$this->expectException(\TypeError::class); |
68
|
|
|
(new FileSystemPath(null)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::rawPath |
73
|
|
|
* @depends testCanBeCreated |
74
|
|
|
*/ |
75
|
|
|
public function testCanRetrieveRawPath(FileSystemPath $systemPath) |
76
|
|
|
{ |
77
|
|
|
$this->assertEquals($this->file, $systemPath->rawPath()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::rawPath |
82
|
|
|
* @depends testCanBeCreated |
83
|
|
|
*/ |
84
|
|
|
public function testCantRetrieveRawPath(FileSystemPath $systemPath) |
85
|
|
|
{ |
86
|
|
|
$this->assertNotEquals($this->imageFile, $systemPath->rawPath()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::pathName |
91
|
|
|
* @depends testCanBeCreated |
92
|
|
|
*/ |
93
|
|
|
public function testCanRetrievePathname(FileSystemPath $systemPath) |
94
|
|
|
{ |
95
|
|
|
$this->assertEquals($this->path, $systemPath->pathName()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::pathName |
100
|
|
|
* @depends testCanBeCreated |
101
|
|
|
*/ |
102
|
|
|
public function testCantRetrievePathname(FileSystemPath $systemPath) |
103
|
|
|
{ |
104
|
|
|
$this->assertNotEquals($this->imageFile, $systemPath->pathName()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::filename |
109
|
|
|
* @depends testCanBeCreated |
110
|
|
|
*/ |
111
|
|
|
public function testCanRetrieveFilename(FileSystemPath $systemPath) |
112
|
|
|
{ |
113
|
|
|
$this->assertEquals($this->files[0], $systemPath->filename()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::filename |
118
|
|
|
* @depends testCanBeCreated |
119
|
|
|
*/ |
120
|
|
|
public function testCantRetrieveFilename(FileSystemPath $systemPath) |
121
|
|
|
{ |
122
|
|
|
$this->assertNotEquals($this->files[1], $systemPath->filename()); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::size |
127
|
|
|
* @depends testCanBeCreated |
128
|
|
|
*/ |
129
|
|
|
public function testCanRetrieveSize(FileSystemPath $systemPath) |
130
|
|
|
{ |
131
|
|
|
$this->assertEquals($this->sizes[0], $systemPath->size()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::size |
136
|
|
|
* @depends testCanBeCreated |
137
|
|
|
*/ |
138
|
|
|
public function testCantRetrieveSize(FileSystemPath $systemPath) |
139
|
|
|
{ |
140
|
|
|
$this->assertNotEquals($this->sizes[1], $systemPath->size()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::type |
145
|
|
|
* @depends testCanBeCreated |
146
|
|
|
*/ |
147
|
|
|
public function testCanRetrieveType(FileSystemPath $systemPath) |
148
|
|
|
{ |
149
|
|
|
$this->assertEquals($this->types[0], $systemPath->type()); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::type |
154
|
|
|
* @depends testCanBeCreated |
155
|
|
|
*/ |
156
|
|
|
public function testCantRetrieveType(FileSystemPath $systemPath) |
157
|
|
|
{ |
158
|
|
|
$this->assertNotEquals($this->types[1], $systemPath->type()); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::exists |
163
|
|
|
* @depends testCanBeCreated |
164
|
|
|
*/ |
165
|
|
|
public function testExists(FileSystemPath $systemPath) |
166
|
|
|
{ |
167
|
|
|
$this->assertTrue($systemPath->exists()); |
168
|
|
|
$this->assertFileExists($this->file, $systemPath->rawPath()); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::exists |
173
|
|
|
*/ |
174
|
|
|
public function testNotExists() |
175
|
|
|
{ |
176
|
|
|
$path = new FileSystemPath($this->notExistsFile); |
177
|
|
|
$this->assertFalse($path->exists()); |
178
|
|
|
$this->assertFileNotExists($this->notExistsFile, $path->rawPath()); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @covers \LazyEight\DiTesto\FileSystem\FileSystemPath::isDirectory |
183
|
|
|
*/ |
184
|
|
|
public function testIsDirectory() |
185
|
|
|
{ |
186
|
|
|
$this->assertTrue((new FileSystemPath($this->path))->isDirectory()); |
187
|
|
|
$this->assertFalse((new FileSystemPath($this->file))->isDirectory()); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|