. * * @file * @ingroup extensions */ use Popups\PopupsContext; use Popups\PopupsGadgetsIntegration; use Popups\EventLogging\EventLogger; use Popups\EventLogging\NullLogger; /** * Create an initializable Popups context. * It's bit dirty approach but we do not have a DependencyInject/ServiceLocator for extension * modules and we don't want to put tests-related logic inside real classes. * * This wrapper extends PopupsContext and allows to Initialize context by creating new instance * and allows to override/reset cached static PopupsContext instance. * * Used for testing only * @codeCoverageIgnore */ class PopupsContextTestWrapper extends PopupsContext { /** * Override constructor so we can create new instances for testing. * * @param Config $config * @param ExtensionRegistry $extensionRegistry * @param PopupsGadgetsIntegration|null $gadgetsIntegration * @param EventLogger|null $eventLogger */ public function __construct( Config $config, ExtensionRegistry $extensionRegistry, PopupsGadgetsIntegration $gadgetsIntegration = null, EventLogger $eventLogger = null ) { $gadgetsIntegration = $gadgetsIntegration ? $gadgetsIntegration : new PopupsGadgetsIntegration( $config, $extensionRegistry ); $eventLogger = $eventLogger ? $eventLogger : new NullLogger(); parent::__construct( $config, $extensionRegistry, $gadgetsIntegration, $eventLogger ); } /** * Allow to reset cached instance */ public static function resetTestInstance() { self::$instance = null; } /** * Override cached instance * * @param PopupsContext $testInstance */ public static function injectTestInstance( PopupsContext $testInstance ) { self::$instance = $testInstance; } }