Closed derrabus closed 2 months ago
you could check that getFunctions
or getFilters
is not called on a registered extension as a way to detect that the initialization is not performed (which also does not require mocking the Environment AFAIK).
I tried your suggestion:
$twig = new Environment($loader, $options);
$extension = $this->createMock(ExtensionInterface::class);
$extension->expects($this->never())->method($this->anything());
$twig->addExtension($extension);
With this, the test fails. My assumption is that the test guesses the cache key wrong.
Adding the extension changes the cache key. 🤦🏻♂️ I'll try to work around that.
I think, I've fixed the test. Thank you for your help, @stof.
Thank you @derrabus.
I stumbled over this test while checking for PHPUnit deprecations. In this case, we need to do something about the
setMethods()
call which has been removed in PHPUnit 11.However, we add an expectation for a method
initExtensions()
which has been removed a long time ago. So, if that method was actually called, we'd get an error anyway. Expecting this method not to be called feels a little redundant.This basically means, we can run this test against an unmockedEnvironment
. But if we do so, the test does not really test what it's supposed to test which is why I decided to remove the whole test.Update: Instead, I'm now registering an extension that throws if we try to initialize it.