public function ChainMatcherTest::testRequestFound

Confirms that the expected exception is thrown.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Routing/ChainMatcherTest.php, line 83
Definition of Drupal\system\Tests\Routing\ChainMatcherTest.

Class

ChainMatcherTest
Basic tests for the ChainMatcher.

Namespace

Drupal\system\Tests\Routing

Code

public function testRequestFound() {
  $chain = new ChainMatcher();
  $method_not_allowed = new MockMatcher(function (Request $request) {
    throw new MethodNotAllowedException(array(
      'POST',
    ));
  });
  $resource_not_found = new MockMatcher(function (Request $request) {
    throw new ResourceNotFoundException();
  });
  $found_data = new MockMatcher(function (Request $request) {
    return array(
      '_controller' => 'foo',
    );
  });
  try {
    $chain
      ->add($method_not_allowed);
    $chain
      ->add($resource_not_found);
    $chain
      ->add($found_data);
    $request = Request::create('my/path');
    $attributes = $chain
      ->matchRequest($request);
    $this
      ->assertEqual($attributes['_controller'], 'foo', 'Correct attributes returned.');
  } catch (Exception $e) {
    $this
      ->fail('Exception thrown when a match should have been successful: ' . get_class($e));
  }
}