Commit 2873e817 authored by alexpott's avatar alexpott

Issue #2526412 by neclimdul, hussainweb, Fabianx: Remove Singleton hack in...

Issue #2526412 by neclimdul, hussainweb, Fabianx: Remove Singleton hack in registerWithSymfonyGuesser
parent 6f78b08d
......@@ -118,21 +118,9 @@ protected function sortGuessers() {
* @see \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
*/
public static function registerWithSymfonyGuesser(ContainerInterface $container) {
// Reset state, so we do not store more and more services during test runs.
SymfonyMimeTypeGuesser::reset();
$singleton = SymfonyMimeTypeGuesser::getInstance();
// @todo Remove once Symfony adds a reset() method.
$property = new \ReflectionProperty(get_class($singleton), 'guessers');
$property->setAccessible(TRUE);
if (isset($singleton->_beforeDrupalRegistration)) {
// Reset state, else we store more and more services during test runs.
$property->setValue($singleton, $singleton->_beforeDrupalRegistration);
} else {
// Store original state before we register our services.
$singleton->_beforeDrupalRegistration = $property->getValue($singleton);
}
//$singleton->reset();
$singleton->register($container->get('file.mime_type.guesser'));
}
......
......@@ -37,14 +37,18 @@ public function testSymfonyGuesserRegistration() {
$container = new ContainerBuilder();
$container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
MimeTypeGuesser::registerWithSymfonyGuesser($container);
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
$guessers = $this->readAttribute($symfony_guesser, 'guessers');
$this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
$this->assertInstanceOf('Drupal\Core\File\MimeType\MimeTypeGuesser', $guessers[0]);
$count = count($guessers);
$container = new ContainerBuilder();
$container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
MimeTypeGuesser::registerWithSymfonyGuesser($container);
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
$guessers = $this->readAttribute($symfony_guesser, 'guessers');
$this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]);
$this->assertInstanceOf('Drupal\Core\File\MimeType\MimeTypeGuesser', $guessers[0]);
$new_count = count($guessers);
$this->assertEquals($count, $new_count, 'The count of mime type guessers remains the same after container re-init.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment