public function ChainRouterTest::testSortRouters

Routers are supposed to be sorted only once. This test will check that by trying to get all routers several times.

@covers \Symfony\Cmf\Component\Routing\ChainRouter::sortRouters @covers \Symfony\Cmf\Component\Routing\ChainRouter::all

File

drupal/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Tests/Routing/ChainRouterTest.php, line 41

Class

ChainRouterTest

Namespace

Symfony\Cmf\Component\Routing\Tests\Routing

Code

public function testSortRouters() {
  list($low, $medium, $high) = $this
    ->createRouterMocks();

  // We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
  $router = $this
    ->buildMock('Symfony\\Cmf\\Component\\Routing\\ChainRouter', array(
    'sortRouters',
  ));
  $router
    ->expects($this
    ->once())
    ->method('sortRouters')
    ->will($this
    ->returnValue(array(
    $high,
    $medium,
    $low,
  )));
  $router
    ->add($low, 10);
  $router
    ->add($medium, 50);
  $router
    ->add($high, 100);
  $expectedSortedRouters = array(
    $high,
    $medium,
    $low,
  );

  // Let's get all routers 5 times, we should only sort once.
  for ($i = 0; $i < 5; ++$i) {
    $this
      ->assertSame($expectedSortedRouters, $router
      ->all());
  }
}