@@ -28,10 +28,16 @@ public function testGetPathReturnsAbsolutePath()
28
28
$ this ->assertEquals (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' .DIRECTORY_SEPARATOR .'test.gif ' , $ this ->file ->getPath ());
29
29
}
30
30
31
+ public function test__toString ()
32
+ {
33
+ $ this ->assertEquals (__DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' .DIRECTORY_SEPARATOR .'test.gif ' , (string ) $ this ->file );
34
+ }
35
+
31
36
public function testGetWebPathReturnsPathRelativeToDocumentRoot ()
32
37
{
33
38
File::setDocumentRoot (__DIR__ );
34
39
40
+ $ this ->assertEquals (__DIR__ , File::getDocumentRoot ());
35
41
$ this ->assertEquals ('/Fixtures/test.gif ' , $ this ->file ->getWebPath ());
36
42
}
37
43
@@ -42,11 +48,24 @@ public function testGetWebPathReturnsEmptyPathIfOutsideDocumentRoot()
42
48
$ this ->assertEquals ('' , $ this ->file ->getWebPath ());
43
49
}
44
50
51
+ public function testSetDocumentRootThrowsLogicExceptionWhenNotExists ()
52
+ {
53
+ $ this ->setExpectedException ('LogicException ' );
54
+
55
+ File::setDocumentRoot (__DIR__ .'/Fixtures/not_here ' );
56
+ }
57
+
45
58
public function testGetNameReturnsNameWithExtension ()
46
59
{
47
60
$ this ->assertEquals ('test.gif ' , $ this ->file ->getName ());
48
61
}
49
62
63
+ public function testGetExtensionReturnsEmptyString ()
64
+ {
65
+ $ file = new File (__DIR__ .'/Fixtures/test ' );
66
+ $ this ->assertEquals ('' , $ file ->getExtension ());
67
+ }
68
+
50
69
public function testGetExtensionReturnsExtensionWithDot ()
51
70
{
52
71
$ this ->assertEquals ('.gif ' , $ this ->file ->getExtension ());
@@ -66,6 +85,13 @@ public function testGetMimeTypeUsesMimeTypeGuessers()
66
85
$ this ->assertEquals ('image/gif ' , $ this ->file ->getMimeType ());
67
86
}
68
87
88
+ public function testGetDefaultExtensionWithoutGuesser ()
89
+ {
90
+ $ file = new File (__DIR__ .'/Fixtures/directory/.empty ' );
91
+
92
+ $ this ->assertEquals ('.empty ' , $ file ->getDefaultExtension ());
93
+ }
94
+
69
95
public function testGetDefaultExtensionIsBasedOnMimeType ()
70
96
{
71
97
$ file = new File (__DIR__ .'/Fixtures/test ' );
@@ -76,11 +102,33 @@ public function testGetDefaultExtensionIsBasedOnMimeType()
76
102
$ this ->assertEquals ('.gif ' , $ file ->getDefaultExtension ());
77
103
}
78
104
105
+ public function testConstructWhenFileNotExists ()
106
+ {
107
+ $ this ->setExpectedException ('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException ' );
108
+
109
+ new File (__DIR__ .'/Fixtures/not_here ' );
110
+ }
111
+
79
112
public function testSizeReturnsFileSize ()
80
113
{
81
114
$ this ->assertEquals (filesize ($ this ->file ->getPath ()), $ this ->file ->size ());
82
115
}
83
116
117
+ public function testSizeFailing ()
118
+ {
119
+ $ dir = __DIR__ .DIRECTORY_SEPARATOR .'Fixtures ' .DIRECTORY_SEPARATOR .'directory ' ;
120
+ $ path = $ dir .DIRECTORY_SEPARATOR .'test.copy.gif ' ;
121
+ @unlink ($ path );
122
+ copy (__DIR__ .'/Fixtures/test.gif ' , $ path );
123
+
124
+ $ file = new File ($ path );
125
+ @unlink ($ path );
126
+
127
+ $ this ->setExpectedException ('Symfony\Component\HttpFoundation\File\Exception\FileException ' );
128
+ $ file ->size ($ path );
129
+
130
+ }
131
+
84
132
public function testMove ()
85
133
{
86
134
$ path = __DIR__ .'/Fixtures/test.copy.gif ' ;
@@ -121,6 +169,27 @@ public function testMoveWithNewName()
121
169
@unlink ($ targetPath );
122
170
}
123
171
172
+ public function testMoveFailing ()
173
+ {
174
+ $ path = __DIR__ .'/Fixtures/test.copy.gif ' ;
175
+ $ targetPath = '/thisfolderwontexist ' ;
176
+ @unlink ($ path );
177
+ @unlink ($ targetPath );
178
+ copy (__DIR__ .'/Fixtures/test.gif ' , $ path );
179
+
180
+ $ file = new File ($ path );
181
+
182
+ $ this ->setExpectedException ('Symfony\Component\HttpFoundation\File\Exception\FileException ' );
183
+ $ file ->move ($ targetPath );
184
+
185
+ $ this ->assertFileExists ($ path );
186
+ $ this ->assertFileNotExists ($ path .$ targetPath .'test.gif ' );
187
+ $ this ->assertEquals ($ path , $ file ->getPath ());
188
+
189
+ @unlink ($ path );
190
+ @unlink ($ targetPath );
191
+ }
192
+
124
193
public function testRename ()
125
194
{
126
195
$ path = __DIR__ .'/Fixtures/test.copy.gif ' ;
0 commit comments