forked from thephpleague/flysystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlerTests.php
More file actions
153 lines (138 loc) · 5.05 KB
/
HandlerTests.php
File metadata and controls
153 lines (138 loc) · 5.05 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
use League\Flysystem\Directory;
use League\Flysystem\File;
use Prophecy\PhpUnit\ProphecyTestCase;
class HandlerTests extends ProphecyTestCase
{
public function testFileRead()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->read('path.txt')->willReturn('contents');
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$output = $file->read();
$this->assertEquals('contents', $output);
}
public function testFileDelete()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->delete('path.txt')->willReturn(true);
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$output = $file->delete();
$this->assertTrue($output);
}
public function testFileReadStream()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->readStream('path.txt')->willReturn('contents');
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$output = $file->readStream();
$this->assertEquals('contents', $output);
}
public function testFileUpdate()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->update('path.txt', 'contents')->willReturn(true);
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$output = $file->update('contents');
$this->assertTrue($output);
}
public function testFileUpdateStream()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->updateStream('path.txt', 'contents')->willReturn(true);
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$output = $file->updateStream('contents');
$this->assertTrue($output);
}
public function getterProvider()
{
return [
['getTimestamp', 123],
['getMimetype', 'text/plain'],
['getVisibility', 'private'],
['getMetadata', ['some' => 'metadata']],
['getSize', 123],
];
}
/**
* @dataProvider getterProvider
*
* @param $method
* @param $response
*/
public function testGetters($method, $response)
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->{$method}('path.txt')->willReturn($response);
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$output = $file->{$method}();
$this->assertEquals($response, $output);
}
public function testFileIsFile()
{
$response = ['type' => 'file'];
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->getMetadata('path.txt')->willReturn($response);
$filesystem = $prophecy->reveal();
$file = new File(null, 'path.txt');
$file->setFilesystem($filesystem);
$this->assertTrue($file->isFile());
}
public function testFileIsDir()
{
$response = ['type' => 'file'];
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->getMetadata('path.txt')->willReturn($response);
$filesystem = $prophecy->reveal();
$file = new File();
$file->setPath('path.txt');
$file->setFilesystem($filesystem);
$this->assertFalse($file->isDir());
}
public function testFileGetPath()
{
$file = new File();
$file->setPath('path.txt');
$this->assertEquals('path.txt', $file->getPath());
}
public function testDirDelete()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->deleteDir('path')->willReturn(true);
$filesystem = $prophecy->reveal();
$dir = new Directory(null, 'path');
$dir->setFilesystem($filesystem);
$output = $dir->delete();
$this->assertTrue($output);
}
public function testDirListContents()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$prophecy->listContents('path', true)->willReturn($listing = ['listing']);
$filesystem = $prophecy->reveal();
$dir = new Directory(null, 'path');
$dir->setFilesystem($filesystem);
$output = $dir->getContents(true);
$this->assertEquals($listing, $output);
}
public function testGetFilesystem()
{
$prophecy = $this->prophesize('League\Flysystem\FilesystemInterface');
$filesystem = $prophecy->reveal();
$dir = new Directory(null, 'path');
$dir->setFilesystem($filesystem);
$this->assertEquals($filesystem, $dir->getFilesystem());
}
}