1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Gaufrette\Adapter\Local; |
4
|
|
|
|
5
|
|
|
use Gaufrette\Adapter\Local\LocalStream; |
6
|
|
|
use org\bovigo\vfs\vfsStream; |
7
|
|
|
use PhpSpec\ObjectBehavior; |
8
|
|
|
|
9
|
|
|
class LocalSpec extends ObjectBehavior |
10
|
|
|
{ |
11
|
|
|
function let() |
12
|
|
|
{ |
13
|
|
|
vfsStream::setup('test'); |
14
|
|
|
vfsStream::copyFromFileSystem(__DIR__.'/MockFilesystem'); |
15
|
|
|
$this->beConstructedWith(vfsStream::url('test')); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
function it_is_adapter() |
19
|
|
|
{ |
20
|
|
|
$this->shouldHaveType('Gaufrette\Adapter'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function it_is_checksum_calculator() |
24
|
|
|
{ |
25
|
|
|
$this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_a_mime_type_provider() |
29
|
|
|
{ |
30
|
|
|
$this->shouldHaveType('Gaufrette\Adapter\MimeTypeProvider'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_gets_the_file_mime_type() |
34
|
|
|
{ |
35
|
|
|
$this->mimeType('filename')->shouldReturn('text/plain'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_is_stream_factory() |
39
|
|
|
{ |
40
|
|
|
$this->shouldHaveType('Gaufrette\Adapter\StreamFactory'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_reads_file() |
44
|
|
|
{ |
45
|
|
|
$this->read('filename')->shouldReturn("content\n"); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function it_writes_file() |
49
|
|
|
{ |
50
|
|
|
$this->write('filename', 'some content')->shouldReturn(12); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_renames_file() |
54
|
|
|
{ |
55
|
|
|
$this->rename('filename', 'aaa/filename2')->shouldReturn(true); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function it_checks_if_file_exists() |
59
|
|
|
{ |
60
|
|
|
$this->exists('filename')->shouldReturn(true); |
61
|
|
|
$this->exists('filename1')->shouldReturn(false); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_fetches_keys() |
65
|
|
|
{ |
66
|
|
|
$expectedKeys = array('filename', 'dir', 'dir/file'); |
67
|
|
|
sort($expectedKeys); |
68
|
|
|
$this->keys()->shouldReturn($expectedKeys); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function it_fetches_mtime() |
72
|
|
|
{ |
73
|
|
|
$mtime = filemtime(vfsStream::url('test/filename')); |
74
|
|
|
$this->mtime('filename')->shouldReturn($mtime); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function it_deletes_file() |
78
|
|
|
{ |
79
|
|
|
$this->delete('filename')->shouldReturn(true); |
80
|
|
|
$this->delete('filename1')->shouldReturn(false); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function it_checks_if_given_key_is_directory() |
84
|
|
|
{ |
85
|
|
|
$this->isDirectory('dir')->shouldReturn(true); |
86
|
|
|
$this->isDirectory('filename')->shouldReturn(false); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function it_creates_local_stream() |
90
|
|
|
{ |
91
|
|
|
$this->createStream('filename')->shouldReturnAnInstanceOf(LocalStream::class); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function it_does_not_allow_to_read_path_above_main_file_directory() |
95
|
|
|
{ |
96
|
|
|
$this |
97
|
|
|
->shouldThrow(new \OutOfBoundsException(sprintf('The path "%s" is out of the filesystem.', vfsStream::url('filename')))) |
98
|
|
|
->duringRead('../filename') |
99
|
|
|
; |
100
|
|
|
$this |
101
|
|
|
->shouldThrow(new \OutOfBoundsException(sprintf('The path "%s" is out of the filesystem.', vfsStream::url('filename')))) |
102
|
|
|
->duringExists('../filename') |
103
|
|
|
; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
function it_fails_when_directory_does_not_exists() |
107
|
|
|
{ |
108
|
|
|
$this->beConstructedWith(vfsStream::url('other')); |
109
|
|
|
|
110
|
|
|
$this |
111
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
112
|
|
|
->duringRead('filename') |
113
|
|
|
; |
114
|
|
|
$this |
115
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
116
|
|
|
->duringWrite('filename', 'some content') |
117
|
|
|
; |
118
|
|
|
$this |
119
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
120
|
|
|
->duringRename('filename', 'otherFilename') |
121
|
|
|
; |
122
|
|
|
$this |
123
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
124
|
|
|
->duringExists('filename') |
125
|
|
|
; |
126
|
|
|
$this |
127
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
128
|
|
|
->duringKeys() |
129
|
|
|
; |
130
|
|
|
$this |
131
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
132
|
|
|
->duringMtime('filename') |
133
|
|
|
; |
134
|
|
|
$this |
135
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
136
|
|
|
->duringDelete('filename') |
137
|
|
|
; |
138
|
|
|
$this |
139
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
140
|
|
|
->duringIsDirectory('filename') |
141
|
|
|
; |
142
|
|
|
$this |
143
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
144
|
|
|
->duringCreateStream('filename') |
145
|
|
|
; |
146
|
|
|
$this |
147
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
148
|
|
|
->duringChecksum('filename') |
149
|
|
|
; |
150
|
|
|
$this |
151
|
|
|
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other')))) |
152
|
|
|
->duringMimeType('filename') |
153
|
|
|
; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
function it_creates_directory_when_does_not_exists() |
157
|
|
|
{ |
158
|
|
|
$this->beConstructedWith(vfsStream::url('test/other'), true); |
159
|
|
|
|
160
|
|
|
$this->exists('/')->shouldReturn(true); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|