Skip to content

Commit 5d0c972

Browse files
committed
FIX #27299 AbstractController::resetRequest(), automatically setDispatched(false) before each AbstractController::dispatch()
1 parent a66a2d5 commit 5d0c972

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@
77
/**
88
* Abstract class for the controller tests
99
*/
10+
1011
namespace Magento\TestFramework\TestCase;
1112

13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\App\ResponseInterface;
1215
use Magento\Framework\Data\Form\FormKey;
1316
use Magento\Framework\Message\MessageInterface;
1417
use Magento\Framework\Stdlib\CookieManagerInterface;
1518
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
1619
use Magento\Theme\Controller\Result\MessagePlugin;
17-
use Magento\Framework\App\Request\Http as HttpRequest;
18-
use Magento\Framework\App\Response\Http as HttpResponse;
20+
use PHPUnit\Framework\TestCase;
1921

2022
/**
23+
* Set of methods useful for performing requests to Controllers.
24+
*
2125
* @SuppressWarnings(PHPMD.NumberOfChildren)
2226
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2327
*/
24-
abstract class AbstractController extends \PHPUnit\Framework\TestCase
28+
abstract class AbstractController extends TestCase
2529
{
2630
protected $_runCode = '';
2731

@@ -30,12 +34,12 @@ abstract class AbstractController extends \PHPUnit\Framework\TestCase
3034
protected $_runOptions = [];
3135

3236
/**
33-
* @var \Magento\Framework\App\RequestInterface
37+
* @var RequestInterface
3438
*/
3539
protected $_request;
3640

3741
/**
38-
* @var \Magento\Framework\App\ResponseInterface
42+
* @var ResponseInterface
3943
*/
4044
protected $_response;
4145

@@ -103,8 +107,9 @@ protected function assertPostConditions()
103107
*/
104108
public function dispatch($uri)
105109
{
106-
/** @var HttpRequest $request */
107110
$request = $this->getRequest();
111+
112+
$request->setDispatched(false);
108113
$request->setRequestUri($uri);
109114
if ($request->isPost()
110115
&& !array_key_exists('form_key', $request->getPost())
@@ -119,25 +124,36 @@ public function dispatch($uri)
119124
/**
120125
* Request getter
121126
*
122-
* @return \Magento\Framework\App\RequestInterface|HttpRequest
127+
* @return RequestInterface
123128
*/
124129
public function getRequest()
125130
{
126131
if (!$this->_request) {
127-
$this->_request = $this->_objectManager->get(\Magento\Framework\App\RequestInterface::class);
132+
$this->_request = $this->_objectManager->get(RequestInterface::class);
128133
}
129134
return $this->_request;
130135
}
131136

137+
/**
138+
* Reset Request parameters
139+
*
140+
* @return void
141+
*/
142+
protected function resetRequest(): void
143+
{
144+
$this->_objectManager->removeSharedInstance(RequestInterface::class);
145+
$this->_request = null;
146+
}
147+
132148
/**
133149
* Response getter
134150
*
135-
* @return \Magento\Framework\App\ResponseInterface|HttpResponse
151+
* @return ResponseInterface
136152
*/
137153
public function getResponse()
138154
{
139155
if (!$this->_response) {
140-
$this->_response = $this->_objectManager->get(\Magento\Framework\App\ResponseInterface::class);
156+
$this->_response = $this->_objectManager->get(ResponseInterface::class);
141157
}
142158
return $this->_response;
143159
}

dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ public function testCreatepasswordActionInvalidToken()
188188
}
189189

190190
/**
191-
* @param int $customerId
191+
* @param int $customerId
192192
* @param string|null $confirmation
193193
*/
194194
private function assertCustomerConfirmationEquals(int $customerId, string $confirmation = null)
195195
{
196196
/** @var \Magento\Customer\Model\Customer $customer */
197197
$customer = Bootstrap::getObjectManager()
198-
->create(\Magento\Customer\Model\Customer::class)->load($customerId);
198+
->create(\Magento\Customer\Model\Customer::class)->load($customerId);
199199
$this->assertEquals($confirmation, $customer->getConfirmation());
200200
}
201201

@@ -492,14 +492,14 @@ public function testChangePasswordEditPostAction()
492492
->setMethod('POST')
493493
->setPostValue(
494494
[
495-
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
496-
'firstname' => 'John',
497-
'lastname' => 'Doe',
498-
'email' => 'johndoe@email.com',
499-
'change_password' => 1,
500-
'change_email' => 1,
495+
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
496+
'firstname' => 'John',
497+
'lastname' => 'Doe',
498+
'email' => 'johndoe@email.com',
499+
'change_password' => 1,
500+
'change_email' => 1,
501501
'current_password' => 'password',
502-
'password' => 'new-Password1',
502+
'password' => 'new-Password1',
503503
'password_confirmation' => 'new-Password1',
504504
]
505505
);
@@ -645,6 +645,7 @@ public function testRegisterCustomerWithEmailConfirmation(): void
645645
/** @var CookieManagerInterface $cookieManager */
646646
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
647647
$cookieManager->deleteCookie(MessagePlugin::MESSAGES_COOKIES_NAME);
648+
648649
$this->_objectManager->removeSharedInstance(Http::class);
649650
$this->_objectManager->removeSharedInstance(Request::class);
650651
$this->_request = null;
@@ -761,8 +762,9 @@ public function testResetPasswordWhenEmailChanged(): void
761762
$customer->setEmail($newEmail);
762763
$customerRepository->save($customer);
763764

764-
/* Goes through the link in a mail */
765765
$this->resetRequest();
766+
767+
/* Goes through the link in a mail */
766768
$this->getRequest()
767769
->setParam('token', $token)
768770
->setParam('id', $customerData->getId());
@@ -842,15 +844,13 @@ private function assertForgotPasswordEmailContent(string $token): void
842844
}
843845

844846
/**
845-
* Clear request object.
846-
*
847-
* @return void
847+
* @inheritDoc
848848
*/
849-
private function resetRequest(): void
849+
protected function resetRequest(): void
850850
{
851851
$this->_objectManager->removeSharedInstance(Http::class);
852852
$this->_objectManager->removeSharedInstance(Request::class);
853-
$this->_request = null;
853+
parent::resetRequest();
854854
}
855855

856856
/**

0 commit comments

Comments
 (0)