forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilesystemTest.php
More file actions
executable file
·129 lines (104 loc) · 3.58 KB
/
FilesystemTest.php
File metadata and controls
executable file
·129 lines (104 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
use Illuminate\Filesystem\Filesystem;
class FilesystemTest extends PHPUnit_Framework_TestCase {
public function testGetRetrievesFiles()
{
file_put_contents(__DIR__.'/file.txt', 'Hello World');
$files = new Filesystem;
$this->assertEquals('Hello World', $files->get(__DIR__.'/file.txt'));
@unlink(__DIR__.'/file.txt');
}
public function testPutStoresFiles()
{
$files = new Filesystem;
$files->put(__DIR__.'/file.txt', 'Hello World');
$this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt'));
@unlink(__DIR__.'/file.txt');
}
public function testDeleteRemovesFiles()
{
file_put_contents(__DIR__.'/file.txt', 'Hello World');
$files = new Filesystem;
$files->delete(__DIR__.'/file.txt');
$this->assertFalse(file_exists(__DIR__.'/file.txt'));
@unlink(__DIR__.'/file.txt');
}
public function testPrependExistingFiles()
{
$files = new Filesystem;
$files->put(__DIR__.'/file.txt', 'World');
$files->prepend(__DIR__.'/file.txt', 'Hello ');
$this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt'));
@unlink(__DIR__.'/file.txt');
}
public function testPrependNewFiles()
{
$files = new Filesystem;
$files->prepend(__DIR__.'/file.txt', 'Hello World');
$this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt'));
@unlink(__DIR__.'/file.txt');
}
public function testDeleteDirectory()
{
mkdir(__DIR__.'/foo');
file_put_contents(__DIR__.'/foo/file.txt', 'Hello World');
$files = new Filesystem;
$files->deleteDirectory(__DIR__.'/foo');
$this->assertFalse(is_dir(__DIR__.'/foo'));
$this->assertFalse(file_exists(__DIR__.'/foo/file.txt'));
}
public function testCleanDirectory()
{
mkdir(__DIR__.'/foo');
file_put_contents(__DIR__.'/foo/file.txt', 'Hello World');
$files = new Filesystem;
$files->cleanDirectory(__DIR__.'/foo');
$this->assertTrue(is_dir(__DIR__.'/foo'));
$this->assertFalse(file_exists(__DIR__.'/foo/file.txt'));
@rmdir(__DIR__.'/foo');
}
public function testFilesMethod()
{
mkdir(__DIR__.'/foo');
file_put_contents(__DIR__.'/foo/1.txt', '1');
file_put_contents(__DIR__.'/foo/2.txt', '2');
mkdir(__DIR__.'/foo/bar');
$files = new Filesystem;
$this->assertEquals(array(__DIR__.'/foo/1.txt', __DIR__.'/foo/2.txt'), $files->files(__DIR__.'/foo'));
unset($files);
@unlink(__DIR__.'/foo/1.txt');
@unlink(__DIR__.'/foo/2.txt');
@rmdir(__DIR__.'/foo/bar');
@rmdir(__DIR__.'/foo');
}
public function testCopyDirectoryReturnsFalseIfSourceIsntDirectory()
{
$files = new Filesystem;
$this->assertFalse($files->copyDirectory(__DIR__.'/foo/bar/baz/breeze/boom', __DIR__));
}
public function testCopyDirectoryMovesEntireDirectory()
{
mkdir(__DIR__.'/tmp', 0777, true);
file_put_contents(__DIR__.'/tmp/foo.txt', '');
file_put_contents(__DIR__.'/tmp/bar.txt', '');
mkdir(__DIR__.'/tmp/nested', 0777, true);
file_put_contents(__DIR__.'/tmp/nested/baz.txt', '');
$files = new Filesystem;
$files->copyDirectory(__DIR__.'/tmp', __DIR__.'/tmp2');
$this->assertTrue(is_dir(__DIR__.'/tmp2'));
$this->assertTrue(file_exists(__DIR__.'/tmp2/foo.txt'));
$this->assertTrue(file_exists(__DIR__.'/tmp2/bar.txt'));
$this->assertTrue(is_dir(__DIR__.'/tmp2/nested'));
$this->assertTrue(file_exists(__DIR__.'/tmp2/nested/baz.txt'));
unlink(__DIR__.'/tmp/nested/baz.txt');
rmdir(__DIR__.'/tmp/nested');
unlink(__DIR__.'/tmp/bar.txt');
unlink(__DIR__.'/tmp/foo.txt');
rmdir(__DIR__.'/tmp');
unlink(__DIR__.'/tmp2/nested/baz.txt');
rmdir(__DIR__.'/tmp2/nested');
unlink(__DIR__.'/tmp2/foo.txt');
unlink(__DIR__.'/tmp2/bar.txt');
rmdir(__DIR__.'/tmp2');
}
}