class CurrentPathStackTest
Same name and namespace in other branches
- 11.x 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
- class \Drupal\Tests\DrupalTestCase uses \Drupal\Tests\DrupalTestCaseTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\UnitTestCase uses \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \Drupal\Tests\DrupalTestCase
- class \Drupal\Tests\Core\Path\CurrentPathStackTest extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\UnitTestCase uses \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \Drupal\Tests\DrupalTestCase
Expanded class hierarchy of CurrentPathStackTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Path/ CurrentPathStackTest.php, line 17
Namespace
Drupal\Tests\Core\PathView 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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.