14 use PHPUnit\Framework\TestCase;
24 $file =
new File(__DIR__.
'/Fixtures/test.gif');
29 $this->assertEquals(
'image/gif',
$file->getMimeType());
34 $file =
new File(__DIR__.
'/Fixtures/directory/.empty');
36 $this->assertNull(
$file->guessExtension());
41 $file =
new File(__DIR__.
'/Fixtures/test');
46 $this->assertEquals(
'gif',
$file->guessExtension());
54 $file =
new File(__DIR__.
'/Fixtures/other-file.example');
58 $this->assertEquals(
'gif',
$file->guessExtension());
62 $this->assertNull(
$file->guessExtension());
67 $this->{method_exists($this, $_ =
'expectException') ? $_ :
'setExpectedException'}(
'Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
69 new File(__DIR__.
'/Fixtures/not_here');
74 $path = __DIR__.
'/Fixtures/test.copy.gif';
75 $targetDir = __DIR__.
'/Fixtures/directory';
76 $targetPath = $targetDir.
'/test.copy.gif';
79 copy(__DIR__.
'/Fixtures/test.gif', $path);
82 $movedFile =
$file->move($targetDir);
83 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\File\File', $movedFile);
85 $this->assertFileExists($targetPath);
86 $this->assertFileNotExists($path);
87 $this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
94 $path = __DIR__.
'/Fixtures/test.copy.gif';
95 $targetDir = __DIR__.
'/Fixtures/directory';
96 $targetPath = $targetDir.
'/test.newname.gif';
99 copy(__DIR__.
'/Fixtures/test.gif', $path);
102 $movedFile =
$file->move($targetDir,
'test.newname.gif');
104 $this->assertFileExists($targetPath);
105 $this->assertFileNotExists($path);
106 $this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
108 @unlink($targetPath);
114 array(
'original.gif',
'original.gif'),
115 array(
'..\\..\\original.gif',
'original.gif'),
116 array(
'../../original.gif',
'original.gif'),
117 array(
'файлfile.gif',
'файлfile.gif'),
118 array(
'..\\..\\файлfile.gif',
'файлfile.gif'),
119 array(
'../../файлfile.gif',
'файлfile.gif'),
128 $path = __DIR__.
'/Fixtures/'.$sanitizedFilename;
129 $targetDir = __DIR__.
'/Fixtures/directory/';
130 $targetPath = $targetDir.$sanitizedFilename;
132 @unlink($targetPath);
133 copy(__DIR__.
'/Fixtures/test.gif', $path);
136 $movedFile =
$file->move($targetDir, $filename);
137 $this->assertInstanceOf(
'Symfony\Component\HttpFoundation\File\File', $movedFile);
139 $this->assertFileExists($targetPath);
140 $this->assertFileNotExists($path);
141 $this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
143 @unlink($targetPath);
148 $sourcePath = __DIR__.
'/Fixtures/test.copy.gif';
149 $targetDir = __DIR__.
'/Fixtures/directory/sub';
150 $targetPath = $targetDir.
'/test.copy.gif';
151 @unlink($sourcePath);
152 @unlink($targetPath);
154 copy(__DIR__.
'/Fixtures/test.gif', $sourcePath);
157 $movedFile =
$file->move($targetDir);
159 $this->assertFileExists($targetPath);
160 $this->assertFileNotExists($sourcePath);
161 $this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
163 @unlink($sourcePath);
164 @unlink($targetPath);
170 $guesser = $this->getMockBuilder(
'Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface')->getMock();
172 ->expects($this->once())
174 ->with($this->equalTo($path))
175 ->will($this->returnValue($mimeType))