Skip to content

Commit 111f27f

Browse files
authored
ENGCOM-7143: FIX #27299 Consecutive Requests in Integration Tests failing #27300
2 parents 9f99f88 + b0333fb commit 111f27f

File tree

3 files changed

+66
-25
lines changed

3 files changed

+66
-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
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Controller\Adminhtml;
9+
10+
use Magento\TestFramework\TestCase\AbstractBackendController;
11+
12+
/**
13+
* @magentoAppArea adminhtml
14+
*/
15+
class ConsecutiveCallTest extends AbstractBackendController
16+
{
17+
/**
18+
* Consecutive calls were failing due to `$request['dispatched']` not being reset before request
19+
*/
20+
public function testConsecutiveCallShouldNotFail()
21+
{
22+
$this->dispatch('backend/admin/auth/login');
23+
$this->dispatch('backend/admin/auth/login');
24+
}
25+
}

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

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

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

@@ -497,14 +497,14 @@ public function testChangePasswordEditPostAction()
497497
->setMethod('POST')
498498
->setPostValue(
499499
[
500-
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
501-
'firstname' => 'John',
502-
'lastname' => 'Doe',
503-
'email' => '[email protected]',
504-
'change_password' => 1,
505-
'change_email' => 1,
500+
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
501+
'firstname' => 'John',
502+
'lastname' => 'Doe',
503+
'email' => '[email protected]',
504+
'change_password' => 1,
505+
'change_email' => 1,
506506
'current_password' => 'password',
507-
'password' => 'new-Password1',
507+
'password' => 'new-Password1',
508508
'password_confirmation' => 'new-Password1',
509509
]
510510
);
@@ -654,6 +654,7 @@ public function testRegisterCustomerWithEmailConfirmation(): void
654654
/** @var CookieManagerInterface $cookieManager */
655655
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
656656
$cookieManager->deleteCookie(MessagePlugin::MESSAGES_COOKIES_NAME);
657+
657658
$this->_objectManager->removeSharedInstance(Http::class);
658659
$this->_objectManager->removeSharedInstance(Request::class);
659660
$this->_request = null;
@@ -774,8 +775,9 @@ public function testResetPasswordWhenEmailChanged(): void
774775
$customer->setEmail($newEmail);
775776
$customerRepository->save($customer);
776777

777-
/* Goes through the link in a mail */
778778
$this->resetRequest();
779+
780+
/* Goes through the link in a mail */
779781
$this->getRequest()
780782
->setParam('token', $token)
781783
->setParam('id', $customerData->getId());
@@ -855,15 +857,13 @@ private function assertForgotPasswordEmailContent(string $token): void
855857
}
856858

857859
/**
858-
* Clear request object.
859-
*
860-
* @return void
860+
* @inheritDoc
861861
*/
862-
private function resetRequest(): void
862+
protected function resetRequest(): void
863863
{
864864
$this->_objectManager->removeSharedInstance(Http::class);
865865
$this->_objectManager->removeSharedInstance(Request::class);
866-
$this->_request = null;
866+
parent::resetRequest();
867867
}
868868

869869
/**

0 commit comments

Comments
 (0)