Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

Interfering tests due to runtime cache

Open s2b opened this issue 1 year ago • 0 comments

Fluid by default uses a runtime cache to avoid duplicate parsing/compiling of the same template files or strings. While this is reasonable for applications using Fluid, for Fluid's functional tests it can lead to interference between tests. This is why tests currently can't be executed in random order, but must always be run in the same order.

An example for this is ConstantViewHelperTest: Both renderThrowsExceptionOnNonStringValue() and renderThrowsErrorOnUndefinedConstant() use the same template string to test for an exception code. Depending on the order of the test execution, those codes are different because Fluid returns different exceptions for uncached and cached templates (which is an entirely different issue).

The runtime cache comes into effect in TemplateCompiler->has():

        if (isset($this->syntaxTreeInstanceCache[$identifier]) || class_exists($identifier, false)) {
            return true;
        }

(class_exists() is the relevant check)

and then later in TemplateCompiler->get(), where the class is instantiated. To fix this, we probably need to add an option to fluid to add a random value to the identifier per test run.

s2b avatar Aug 18 '24 10:08 s2b