You are here

public function TwigExtensionFiltersTest::testAddFilterException in Components! 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/TwigExtensionFiltersTest.php \Drupal\Tests\components\Unit\TwigExtensionFiltersTest::testAddFilterException()

Tests exceptions during add filter.

@covers ::addFilter

File

tests/src/Unit/TwigExtensionFiltersTest.php, line 244

Class

TwigExtensionFiltersTest
@coversDefaultClass \Drupal\components\Template\TwigExtension @group components

Namespace

Drupal\Tests\components\Unit

Code

public function testAddFilterException() {
  try {
    TwigExtension::addFilter('not-an-array', 'key', 'value');
    $exception = FALSE;
  } catch (\Exception $e) {
    $this
      ->assertStringContainsString('The add filter only works on arrays or "Traversable" objects, got "string".', $e
      ->getMessage());
    $exception = TRUE;
  }
  if (!$exception) {
    $this
      ->fail('Expected Exception, none was thrown.');
  }
}