You are here

public function ChainRouterTest::testSortRouters in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony-cmf/routing/Tests/Routing/ChainRouterTest.php \Symfony\Cmf\Component\Routing\Tests\Routing\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

vendor/symfony-cmf/routing/Tests/Routing/ChainRouterTest.php, line 67

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.

  /** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
  $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());
  }
}