How do I write unit tests that verify a hook is being fired?
So I figured this out. The specific hook engine for unit testing, very conveniently, comes with an injectable mock property.

After grabbing the hook engine with $this-&gt;hookClass = \CRM_Utils_Hook::singleton() you just need to inject a mock object that has a magic __call() method with somthing like:


$this-&gt;hookClass-&gt;setMock($this);


The hook engine will then call your __call($name, $arguments) method with every hook invocation.

You can see a fuller example here (please ignore the reporting stuff going on - I doubt that is best practice! Also the use of the unit test class as the mock is a bit lazy - its probably best to make a new class to provide the mock)