function StreamWrapperTest::testPharStreamWrapperRegistration

Same name in other branches
  1. 7.x modules/simpletest/tests/file.test \StreamWrapperTest::testPharStreamWrapperRegistration()
  2. 9 core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php \Drupal\KernelTests\Core\File\StreamWrapperTest::testPharStreamWrapperRegistration()

Tests that phar stream wrapper is registered as expected.

See also

\Drupal\Core\StreamWrapper\StreamWrapperManager::register()

File

core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php, line 162

Class

StreamWrapperTest
Tests stream wrapper functions.

Namespace

Drupal\KernelTests\Core\File

Code

public function testPharStreamWrapperRegistration() {
    if (!in_array('phar', stream_get_wrappers(), TRUE)) {
        $this->markTestSkipped('There is no phar stream wrapper registered. PHP is probably compiled without phar support.');
    }
    // Ensure that phar is not treated as a valid scheme.
    $stream_wrapper_manager = $this->container
        ->get('stream_wrapper_manager');
    $this->assertFalse($stream_wrapper_manager->getViaScheme('phar'));
    // Ensure that calling register again and unregister do not create errors
    // due to the PharStreamWrapperManager singleton.
    $stream_wrapper_manager->register();
    $this->assertContains('public', stream_get_wrappers());
    $this->assertContains('phar', stream_get_wrappers());
    $stream_wrapper_manager->unregister();
    $this->assertNotContains('public', stream_get_wrappers());
    // This will have reverted to the builtin phar stream wrapper.
    $this->assertContains('phar', stream_get_wrappers());
    $stream_wrapper_manager->register();
    $this->assertContains('public', stream_get_wrappers());
    $this->assertContains('phar', stream_get_wrappers());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.