Problem/Motivation
We currently throw a runtime exception of Twig\Error\RuntimeError when our Twig filter's target isn't what we expect, this is what Twig core does.
But we aren't checking the validity of parameters in any of our Twig filters or functions. The latest version of Drupal core uses PHP's assert to check they are the expected type.
Proposed resolution
Start checking params with assert.
Issue fork components-3209487
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
johnalbinComment #3
johnalbinPHP type hinting is preferred over assert() and this only leaves one use parameter needing an assert, the first positional parameter of the template function.
According to https://github.com/sebastianbergmann/phpunit/issues/1897, its impossible to write a test to check if the assert get triggered because if you write a test case to do that, the PHP assert will fail the test even if you are expecting assert to be triggered.
Comment #5
johnalbinComment #6
johnalbinComment #8
johnalbin