class CurrentPathStackTest

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/Core/Path/CurrentPathStackTest.php \Drupal\Tests\Core\Path\CurrentPathStackTest

Tests Drupal\Core\Path\CurrentPathStack.

Attributes

#[CoversClass(CurrentPathStack::class)] #[Group('Path')]

Hierarchy

Expanded class hierarchy of CurrentPathStackTest

File

core/tests/Drupal/Tests/Core/Path/CurrentPathStackTest.php, line 17

Namespace

Drupal\Tests\Core\Path
View source
class CurrentPathStackTest extends UnitTestCase {
  
  /**
   * Tests that a path is kept per request, defaulting to the path info.
   */
  public function testPathIsKeptPerRequest() : void {
    $request_stack = new RequestStack();
    $current = Request::create('/node/1');
    $request_stack->push($current);
    $stack = new CurrentPathStack($request_stack);
    $other = Request::create('/node/2');
    $this->assertSame('/node/1', $stack->getPath());
    $stack->setPath('/system/path', $other);
    $this->assertSame('/system/path', $stack->getPath($other));
    $this->assertSame('/node/1', $stack->getPath($current));
  }
  
  /**
   * Tests that a request nothing else references is released.
   *
   * Code that matches many synthetic requests against the router in one
   * process, such as re-tracking entity usage from drush, would otherwise keep
   * every one of them for the life of the process.
   */
  public function testRequestNothingElseReferencesIsReleased() : void {
    $stack = new CurrentPathStack(new RequestStack());
    $request = Request::create('/node/1');
    $stack->setPath('/node/1', $request);
    $reference = \WeakReference::create($request);
    unset($request);
    $this->assertNull($reference->get());
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
CurrentPathStackTest::testPathIsKeptPerRequest public function Tests that a path is kept per request, defaulting to the path info.
CurrentPathStackTest::testRequestNothingElseReferencesIsReleased public function Tests that a request nothing else references is released.
DrupalTestCaseTrait::$root protected property The Drupal root directory.
DrupalTestCaseTrait::checkErrorHandlerOnTearDown public function Checks the test error handler after test execution. 1
DrupalTestCaseTrait::checkLegacySymfonyDeprecationHelperEnvVariable public function Checks legacy SYMFONY_DEPRECATIONS_HELPER env variable is not used.
DrupalTestCaseTrait::expectExceptionMessageIs protected function Expects an exactly matching exception message.
DrupalTestCaseTrait::expectExceptionMessageIsOrContains protected function Expects an exception message containing a specified string.
DrupalTestCaseTrait::getDrupalRoot Deprecated protected static function Returns the Drupal root directory. 1
DrupalTestCaseTrait::setDebugDumpHandler public static function Registers the dumper CLI handler when the DebugDump extension is enabled.
DrupalTestCaseTrait::setUpRoot final protected function Ensure that the $root property is set initially.
DrupalTestCaseTrait::skipTestWithAttribute final protected function Supports skipping tests with the Skip attribute.
ExpectDeprecationTrait::expectDeprecation Deprecated public function Adds an expected deprecation.
ExpectDeprecationTrait::regularExpressionForFormatDescription private function
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
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::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUp protected function 380
UnitTestCase::setupMockIterator protected function Set up a traversable class mock to return specific items when iterated.

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