public function TwigExtensionFiltersTest::testSetFilterException in Components! 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/TwigExtensionFiltersTest.php \Drupal\Tests\components\Unit\TwigExtensionFiltersTest::testSetFilterException()
Tests exceptions during set filter.
@covers ::setFilter
File
- tests/
src/ Unit/ TwigExtensionFiltersTest.php, line 143
Class
- TwigExtensionFiltersTest
- @coversDefaultClass \Drupal\components\Template\TwigExtension @group components
Namespace
Drupal\Tests\components\UnitCode
public function testSetFilterException() {
try {
TwigExtension::setFilter('not-an-array', 'key', 'value');
$exception = FALSE;
} catch (\Exception $e) {
$needle = 'The set 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.');
}
}