class MimeTypeGuesserTest
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php \Drupal\Tests\Core\File\MimeTypeGuesserTest
@coversDefaultClass \Drupal\Core\File\MimeType\MimeTypeGuesser @group DrupalKernel
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- class \Drupal\Tests\Core\File\MimeTypeGuesserTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of MimeTypeGuesserTest
File
-
core/
tests/ Drupal/ Tests/ Core/ File/ MimeTypeGuesserTest.php, line 15
Namespace
Drupal\Tests\Core\FileView source
class MimeTypeGuesserTest extends UnitTestCase {
/**
* @covers ::registerWithSymfonyGuesser
*
* @see Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser
*/
public function testSymfonyGuesserRegistration() {
// Make the guessers property accessible on Symfony's MimeTypeGuesser.
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
// Test that the Drupal mime type guess is not being used before the
// override method is called. It is possible that the test environment does
// not support the default guessers.
$reflected_guessers = new \ReflectionProperty($symfony_guesser, 'guessers');
$reflected_guessers->setAccessible(TRUE);
$guessers = $reflected_guessers->getValue($symfony_guesser);
if (count($guessers)) {
$this->assertNotInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]);
}
$container = new ContainerBuilder();
$container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager()));
MimeTypeGuesser::registerWithSymfonyGuesser($container);
$symfony_guesser = SymfonyMimeTypeGuesser::getInstance();
$guessers = $reflected_guessers->getValue($symfony_guesser);
$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 = $reflected_guessers->getValue($symfony_guesser);
$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.');
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
MimeTypeGuesserTest::testSymfonyGuesserRegistration | public | function | @covers ::registerWithSymfonyGuesser | ||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | ||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | ||
UnitTestCase::$randomGenerator | protected | property | The random generator. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | ||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | ||
UnitTestCase::setUp | protected | function | 338 | ||
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.