You are here

public function TwigExtensionFiltersTest::testAddFilterException in Components! 8.2

Same name and namespace in other branches
  1. 3.x 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 304

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) {
    $needle = 'The add filter only works on arrays or "Traversable" objects, got "string".';
    if (method_exists($this, 'assertStringContainsString')) {
      $this
        ->assertStringContainsString($needle, $e
        ->getMessage());
    }
    else {
      $this
        ->assertContains($needle, $e
        ->getMessage());
    }
    $exception = TRUE;
  }
  if (!$exception) {
    $this
      ->fail('Expected Exception, none was thrown.');
  }
}