class LazyRouteCollectionTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php \Drupal\Tests\Core\Routing\LazyRouteCollectionTest
- 11.x core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php \Drupal\Tests\Core\Routing\LazyRouteCollectionTest
@coversDefaultClass \Drupal\Core\Routing\LazyRouteCollection
@group Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Routing\LazyRouteCollectionTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of LazyRouteCollectionTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ LazyRouteCollectionTest.php, line 18
Namespace
Drupal\Tests\Core\RoutingView source
class LazyRouteCollectionTest extends UnitTestCase {
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
private $routeProvider;
/**
* Array of routes indexed by name.
*
* @var array
*/
private $testRoutes;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->routeProvider = $this->createMock(RouteProviderInterface::class);
$this->testRoutes = [
'route_1' => new Route('/route-1'),
'route_2' => new Route('/route-2'),
];
}
/**
* @covers ::getIterator
* @covers ::all
*/
public function testGetIterator() : void {
$this->routeProvider
->expects($this->exactly(2))
->method('getRoutesByNames')
->with(NULL)
->willReturn($this->testRoutes);
$lazyRouteCollection = new LazyRouteCollection($this->routeProvider);
$this->assertEquals($this->testRoutes, (array) $lazyRouteCollection->getIterator());
$this->assertEquals($this->testRoutes, $lazyRouteCollection->all());
}
/**
* @covers ::count
*/
public function testCount() : void {
$this->routeProvider
->method('getRoutesByNames')
->with(NULL)
->willReturn($this->testRoutes);
$lazyRouteCollection = new LazyRouteCollection($this->routeProvider);
$this->assertEquals(2, $lazyRouteCollection->count());
}
/**
* Search for a both an existing and a non-existing route.
*
* @covers ::get
*/
public function testGetName() : void {
// Hit.
$this->routeProvider
->method('getRouteByName')
->with('route_1')
->willReturn($this->testRoutes['route_1']);
$lazyRouteCollection = new LazyRouteCollection($this->routeProvider);
$this->assertEquals($lazyRouteCollection->get('route_1'), $this->testRoutes['route_1']);
// Miss.
$this->routeProvider
->method('getRouteByName')
->with('does_not_exist')
->will($this->throwException(new RouteNotFoundException()));
$lazyRouteCollectionFail = new LazyRouteCollection($this->routeProvider);
$this->assertNull($lazyRouteCollectionFail->get('does_not_exist'));
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
LazyRouteCollectionTest::$routeProvider | private | property | The route provider. | |||
LazyRouteCollectionTest::$testRoutes | private | property | Array of routes indexed by name. | |||
LazyRouteCollectionTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
LazyRouteCollectionTest::testCount | public | function | @covers ::count | |||
LazyRouteCollectionTest::testGetIterator | public | function | @covers ::getIterator @covers ::all |
|||
LazyRouteCollectionTest::testGetName | public | function | Search for a both an existing and a non-existing route. | |||
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. | |||
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. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
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::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.