Commit graph

8 commits

Author SHA1 Message Date
Sam Smith
f18338fadd TemplateParser: Only hash unique files
LightnCandy resolves recursively-defined partials twice, which leads to
the template file being hashed twice. While the cost of hashing the
partial the second time is minimised due to
FileContentsHasher::getFileContentsHash() caching the hash of a file in
APCu, it need not be paid.

Bug: T300210
Change-Id: Id3f62bf32c47f21181b1ec6d77a5ae9a703952b1
2022-02-09 14:12:24 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
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)