Add a way to reset the singleton

This commit is contained in:
Daniel Wehner 2015-06-26 15:47:25 +02:00 committed by Fabien Potencier
parent 8a8a929d5c
commit 0096266009
3 changed files with 19 additions and 0 deletions

View File

@ -67,6 +67,13 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
return self::$instance;
}
/**
* Resets the singleton instance.
*/
public static function reset() {
self::$instance = null;
}
/**
* Registers all natively provided mime type guessers.
*/

View File

@ -45,6 +45,18 @@ class FileTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('gif', $file->guessExtension());
}
public function testGuessExtensionWithReset() {
$file = new File(__DIR__.'/Fixtures/other-file.example');
$guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
MimeTypeGuesser::getInstance()->register($guesser);
$this->assertEquals('gif', $file->guessExtension());
MimeTypeGuesser::reset();
$this->assertNull($file->guessExtension());
}
public function testConstructWhenFileNotExists()
{
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');