Commit graph

25 commits

Author SHA1 Message Date
daniel
477c8952fe HookContainer: add getHookNames method
This proves a way to list all active hooks.
ApiQuerySiteInfo was relying on $ghHooks, which does not contain hooks
that were registered by extensions using the new hook handler system.

Change-Id: Ifae205f22ab4cc7ae0dfd15e994a1921af51b05c
2022-11-16 11:54:39 +00:00
daniel
8e0ae53482 PHPUnit: introduce clearHooks() method.
Since the introduction of the new hooks stystem, it is not possible to
clear all hooks by setting $wgHooks. This would only clear old-style
hooks. This is becoming increasingly problematic as the new hooks system
is adopted by more and more extensions.

Introduce a method that allows tests to reset many or all hooks.
This isn't needed much in core, but extension tests need it.

Change-Id: Ica3eb88fe23fe822d2aadb96ff5d15f80dce0d7b
2022-11-03 13:40:42 +01:00
Alexander Vorwerk
9b09bf3112 Use updated ObjectFactory namespace
Depends-On: I99c5e5664d2401c36a9890f148eba7c25e6e8324
Depends-On: I48ab818b2965da14af15ef370aa83ad9455badd9
Depends-On: I018371e4b77911e56152ca7b2df734afc73f58a5
Change-Id: I04ebdb52102f6191d49a9cc70b1f98308299e72f
2022-03-09 23:04:51 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02: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
Ammarpad
ae369df66d HookContainer: Fix normalization of callback for static handler
Bug: T283540
Change-Id: I80f68d16b64fb1baa6bf4b3ffd4cfe0a441a0fd9
2021-05-25 20:06:16 +01:00
DannyS712
8ded2eb664 HookContainerTest: fix order of use statements
Not caught by phpcs, see T278348

Change-Id: I79811e2f3cb2e135bf9fb3364dd24c996ae108ec
2021-03-24 15:58:35 +00:00
Thiemo Kreuz
c09f4fd6ef Fix and add various type hints
I keep fixing type hints in my local dev environment whenever I
see something that is worth updating. This is what I collected
over the past weeks.

Change-Id: Ia4f1b4bee2019abe4ab0fb0df8164e1b446229e7
2021-02-16 17:22:15 +00: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
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
Umherirrender
4bdaf3af19 tests: Use ::class on exception names
Change-Id: Iadc2eabb7d132a21cffccf5468b92328a64acb4a
2021-01-03 20:47:49 +01:00
daniel
aab5619d4d HookContainer: fix clear() and scopedRegister().
Previously, clear() and scopedRegister() would not disable hook handlers
registered using the new mechanism. Only old style hook handlers would
be suppressed.

The new implementation is based on tombstones: Instead of actually
removing registered handlers to override them, tombstone markers are
put into place to disable existing handlers until the tombstone is
removed again. This allows hook handlers to be disabled temporarily
in a consistent way.

This removes HookContainer::getOriginalHooksForTest(), which is
incompatible with the new logic.

Bug: T255056
Change-Id: I08c1824797ac60a5098a52b5781af8ac4dd38928
2020-09-08 21:07:59 +02:00
Nikki Nikkhoui
7defcf9c15 Fix scopedRegister() handler key
Use a unique key to assign handlers registered via
scopedRegister(). Using unique keys instead of
array indices ensures that handlers registered in other
ways previously (e.g. via global hook registry or via
HookContainer::register() won't be removed).

Remove the temporary hook for AlternateUserMailer
as the ticket it references is for a class that
no longer exists

Bug: T255056
Change-Id: I491f281e60511a5bdd695ac123611e408324ccff
2020-07-22 12:24:22 -07:00
Nikki Nikkhoui
ccc073854c Remove unused HookContainerTest method
Remove an unused private method from HookContainerTest.

Change-Id: Ie158cef343b31209d3d6e2da57176c9049613b19
2020-07-20 09:43:59 -07:00
Tim Starling
d1363015b7 Introduce soft deprecation of hooks
Add a "silent" flag to DeprecatedHooks which causes relevant deprecation
warnings to be suppressed, but still allows call filtering to be used.

Add existing hooks that are documented as deprecated to the array.

Change-Id: Ieeb5e1840fd06d2b7979ef7827ba82bd2a35a2ba
2020-06-04 10:00:55 +10:00
Tim Starling
b3d762e148 Add HookRegistry
Add a HookRegistry interface and two concrete implementations,
representing HookContainer's view of its environment. This simplifies
creation of a HookContainer for testing.

Add MediaWikiTestCaseTrait::createHookContainer() which can be used
in most of the places that were previously creating mock hook
containers. It can also replace setTemporaryHook() in some cases.

Change-Id: I9ce15591dc40b3d717c203fa973141aa45a2500c
2020-05-13 11:51:02 +10:00
Nikki Nikkhoui
8d378e977c Update setTemporaryHook() to use scopedRegister()
The new HookContainer.php introduces a scopedRegister() method for
temporarily setting hooks. Let's use that in MediaWikiUnitTestCase
and MediaWikiIntegrationTestCase instead of directly accessing
global $wgHooks to do so.

Also introduces setTemporaryHook() and removeTemporaryHook()
methods in MWIntegrationTestCase for easily adding/removing of
temporary hooks.

Bug: T250300
Change-Id: I8cefd41b66f882c53646b76de76c51f0d8730f72
2020-05-11 14:12:00 +10:00
Nikki Nikkhoui
ea3e2e8f74 Bring HookContainerTest to unit test standards
- Remove mockDeprecatedHooks in favor of real DeprecatedHooks
- Create mockExtensionRegistry with createNoOpMock to
prevent any non-mocked methods from being called

Change-Id: I8beb25f058fe76bcc436f7e9bc2d55bde7795b35
2020-05-01 17:45:02 +00:00
Tim Starling
3d7365e844 Allow new style hook handlers to abort
Aborting was apparently lost by accident in PS28 of the HookContainer
commit.

In the test, to allow multiple different hooks to be registered, I
used a real ObjectFactory with a fake ServiceContainer, instead of a
fake ObjectFactory. I changed the parameter to
getMockExtensionRegistry() to take the full attribute value instead of
the hook name and a single handler.

Change-Id: I7b4c547737febe81a487fe154db150055ae31344
2020-05-01 08:02:31 +10:00
Tim Starling
6091dca5a6 Fix DeprecatedHooks and move emitDeprecatedHookWarnings to HookContainer
DeprecatedHooks was not listed as a core attribute and so was not
extracted from extension.json. I added some code to extract and merge it
in extractHooks(), and I also made the "component" default to the name
of the extension which deprecates the hook, instead of "MediaWiki".

I added the core deprecated hooks based on the current Hooks::run() calls.

I moved emitDeprecatedHookWarnings() to HookContainer, and to reduce the
performance overhead, arranged for it to be called only on page views.

Change-Id: Idc0cfba782b49398d9e7feaa164fe7692d491bf9
2020-05-01 08:02:25 +10:00
Tim Starling
977ee0730e Change HookContainer's namespace from HookRunner to HookContainer
It makes even less sense now that HookRunner has been modularized, with
API hooks being split out to ApiHookRunner. HookRunner is inherently
local and private and doesn't deserve to be a namespace.

Change-Id: I97ddc56e96c7bfeb1594f4a84619665aee9c401c
2020-04-29 10:58:24 +10:00
Renamed from tests/phpunit/unit/includes/HookRunner/HookContainerTest.php (Browse further)