Skip to content

Commit dd5e798

Browse files
committed
Replace Preference with Plugin
1 parent e4aea96 commit dd5e798

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

TwoFactorAuth/TestFramework/ControllerActionPredispatch.php renamed to TwoFactorAuth/Plugin/BypassTwoFactorAuthForTestFramework.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,33 @@
66

77
declare(strict_types=1);
88

9-
namespace Magento\TwoFactorAuth\TestFramework;
9+
namespace Magento\TwoFactorAuth\Plugin;
1010

1111
use Magento\Backend\App\AbstractAction;
1212
use Magento\Framework\Event\Observer;
13-
use Magento\TwoFactorAuth\Observer\ControllerActionPredispatch as ParentObserver;
13+
use Magento\TestFramework\Request;
14+
use Magento\TwoFactorAuth\Observer\ControllerActionPredispatch;
1415

1516
/**
16-
* Observer that allows integration controller tests that are not aware of 2FA to run.
17+
* Plugin that allows integration controller tests that are not aware of 2FA to run.
1718
*/
18-
class ControllerActionPredispatch extends ParentObserver
19+
class BypassTwoFactorAuthForTestFramework
1920
{
20-
/**
21-
* @inheritDoc
22-
*/
23-
public function execute(Observer $observer)
24-
{
21+
public function aroundExecute(
22+
ControllerActionPredispatch $subject,
23+
Observer $observer,
24+
callable $proceed
25+
) : void {
2526
/** @var $controllerAction AbstractAction */
2627
$controllerAction = $observer->getEvent()->getData('controller_action');
2728
if (method_exists($controllerAction, 'getRequest')
28-
&& $controllerAction->getRequest() instanceof \Magento\TestFramework\Request
29+
&& $controllerAction->getRequest() instanceof Request
2930
&& !$controllerAction->getRequest()->getParam('tfa_enabled')
3031
) {
3132
//Hack that allows integration controller tests that are not aware of 2FA to run
3233
return;
3334
}
3435

35-
parent::execute($observer);
36+
$proceed($observer);
3637
}
3738
}

TwoFactorAuth/etc/di.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
<plugin name="fixDefaultUrl" type="Magento\TwoFactorAuth\Plugin\FirstAvailableMenu"/>
8888
</type>
8989

90+
<type name="Magento\TwoFactorAuth\Observer\ControllerActionPredispatch">
91+
<plugin name="bypass_twofactorauth_testframework" type="Magento\TwoFactorAuth\Plugin\BypassTwoFactorAuthForTestFramework" />
92+
</type>
93+
9094
<virtualType name="Magento\TwoFactorAuth\Model\Provider\Google" type="Magento\TwoFactorAuth\Model\Provider">
9195
<arguments>
9296
<argument name="engine" xsi:type="object">Magento\TwoFactorAuth\Model\Provider\Engine\Google</argument>
@@ -159,5 +163,4 @@
159163
<preference for="Magento\TwoFactorAuth\Api\UserConfigRequestManagerInterface" type="Magento\TwoFactorAuth\Model\UserConfig\UserConfigRequestManager" />
160164
<preference for="Magento\TwoFactorAuth\Api\UserConfigTokenManagerInterface" type="Magento\TwoFactorAuth\Model\UserConfig\SignedTokenManager" />
161165
<preference for="Magento\TwoFactorAuth\Api\UserNotifierInterface" type="Magento\TwoFactorAuth\Model\EmailUserNotifier" />
162-
<preference for="Magento\TwoFactorAuth\Observer\ControllerActionPredispatch" type="Magento\TwoFactorAuth\TestFramework\ControllerActionPredispatch" />
163166
</config>

0 commit comments

Comments
 (0)