You are here

public function TwigExtensionFiltersTest::testRecursiveMergeFilterException in Components! 8.2

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

Tests exceptions during recursive_merge filter.

@covers ::recursiveMergeFilter

File

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

Class

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

Namespace

Drupal\Tests\components\Unit

Code

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