public function ChainMatcherTest::testMethodNotAllowed

Confirms that the expected exception is thrown.

File

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

Class

ChainMatcherTest
Basic tests for the ChainMatcher.

Namespace

Drupal\system\Tests\Routing

Code

public function testMethodNotAllowed() {
  $chain = new ChainMatcher();
  $method_not_allowed = new MockMatcher(function (Request $request) {
    throw new MethodNotAllowedException(array(
      'POST',
    ));
  });
  try {
    $chain
      ->add($method_not_allowed);
    $chain
      ->matchRequest(Request::create('my/path'));
  } catch (MethodNotAllowedException $e) {
    $this
      ->pass('Correct exception thrown.');
  } catch (Exception $e) {
    $this
      ->fail('Incorrect exception thrown: ' . get_class($e));
  }
}