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
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
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
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
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
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
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
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
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
- Remove mockDeprecatedHooks in favor of real DeprecatedHooks
- Create mockExtensionRegistry with createNoOpMock to
prevent any non-mocked methods from being called
Change-Id: I8beb25f058fe76bcc436f7e9bc2d55bde7795b35
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
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
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)