* $callback = function() use ($expected) { * $test->assertContains($expected,$this->message_plain); * }; * MockedNotifications::set_callback($callback); * $this->bo->tracking = new \_tracking($this->bo, MockedNotifications::class); * * * Everything will run as normal except notifications won't be sent, and you can * put assertions into the callback for what you expect of the notification(s). */ class MockedNotifications extends \notifications { static $send_callback; public static function set_callback(\Closure $send) { static::$send_callback = $send; } public function send() { return static::$send_callback->call($this); } }