Commit graph

4 commits

Author SHA1 Message Date
Timo Tijhof
a5e4174d82 TemplateParser: Refactor the two integration test classes
* There were two separate integration test suites, both testing
  the TemplateParser class. One extended MediaWikiTestCase, which is an
  alias for MediaWikiIntegrationTestCase. The other was extending
  MediaWikiIntegrationTestCase directly.

  I've merged these into the same file.

* Use an injected BagOStuff instance.

  This means we can inject a mock and more cleanly assert the
  subject class' observable behaviour and contract toward BagOStuff,
  without hardcoding any internal details of TemplateParser.

* Add coverage for getTemplate() not using the cache in any way
  when wgSecretKey is false.

Change-Id: Ic01f23b1d59c430ab6adf247e0244514b98e20b8
2020-03-23 21:54:47 +00:00
Timo Tijhof
e4b7341fb6 TemplateParser: Inject BagOStuff and deprecate '$forceRecompile'
* Injecting the cache object makes the class easier to test.

* The $forceRecompile parameter was not used anywhere, not tested,
  and only mentioned in one README (fixed in I13fba7314).
  Based on past experience I generally expect that when bypassing a
  cache, it is neither read from nor written to. Such feature might
  be reached out to when testing something, in which case it should
  not be stored.

  If this was intended as a way to purge it in prod via eval.php,
  we generally don't provide dedicated purging commands in code.
  We either call BagOStuff or Memc/Apcu directly, or invalidate the
  underlying data (e.g. touch the template file, or bump the cache
  version).

  To use TemplateParser without caching, one can still pass
  'new EmptyBagOStuff' instead if needed.

* Set the $ttl parameter in the set() call.
  It is generally an anti-pattern to store something without
  any TTL as that means it can needlessly compete for space
  even after further deployments have changed the key or stopped
  using a particular key. For now I used a liberal default
  of 1 week.

Change-Id: Ic84b996b46c72e9dc33eed2645204fc2d6c5240c
2020-03-23 20:09:05 +00:00
Sam Smith
d4be8b9c08 TemplateParser: Include template dir in cache key
Template names aren't expected to be globally unique. Template paths are
by construction.

Include the template directory in the cache key in order to avoid the
cache keys of ambiguosly-named templates - e.g. index.mustache -
overriding one another.

Bug: T113095
Bug: T248010
Change-Id: I3196967ec2a7a5cec409a0c7ce4471a7d8773978
2020-03-18 21:57:34 +00:00
Reedy
abf2463056 Rename TemplateParserTest.php -> TemplateParserIntegrationTest.php
Follows-up 419bbcd8f9.

We already have a TemplateParserTest.php and class.

Bug: T113095
Change-Id: Id4c18a3d1706865df60f9d1bff73d8c454196224
2020-03-08 18:41:33 +00:00
Renamed from tests/phpunit/integration/includes/TemplateParserTest.php (Browse further)