Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Unit tests would like to disable all potential side effects. That means FileCacheFactory::get() should always return a NullFileCache class.
They do so by calling:
FileCacheFactory::setConfiguration(['default' => ['class' => NullFileCache::class]]);
That however will not be reliable in case a backend specified a different class itself.
Proposed resolution
- Add:
$conf['file_cache']['file_cache_disable'] = TRUE;
or
FileCacheFactory::setConfiguration(['file_cache_disable' => TRUE]]);
which acts like a global kill switch for the FileCache and will it have to use the NullFileCache directly.
Remaining tasks
- Discuss
- Do it
- Write unit tests to test it
Comment | File | Size | Author |
---|---|---|---|
#10 | provide_a_setting_to-2756307-10.patch | 3.99 KB | Fabianx |
#10 | interdiff.txt | 1.32 KB | Fabianx |
Comments
Comment #2
Fabianx CreditAttribution: Fabianx as a volunteer commentedComment #3
dawehnerOption a) seems to be a good approach. Sadly we cannot avoid that classes specify their own default backends.
Comment #4
Fabianx CreditAttribution: Fabianx as a volunteer commentedComment #5
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedHere is the patch.
Comment #6
dawehnerAdded a really quick CR, we have tests already.
Comment #7
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAdded a FileCacheFactory::DISABLE_CACHE constant per idea by dawehner. (Much better!)
Comment #8
dawehnerThank you @Fabianx!
Comment #9
alexpottThis unset looks really strange. I think it would be best to make setUp() like this:
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI agree.
This was pre-existing before UnitTestCase disabled the FileCache, where we wanted to keep the current configuration to avoid leaking into global state.
Fixed in attached patch!
Comment #11
alexpottCommitted 57ad987 and pushed to 8.2.x. Thanks!