Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #27299 Consecutive Requests in Integration Tests failing #27300

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
/**
* Abstract class for the controller tests
*/

namespace Magento\TestFramework\TestCase;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
use Magento\Theme\Controller\Result\MessagePlugin;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\App\Response\Http as HttpResponse;
use PHPUnit\Framework\TestCase;

/**
* Set of methods useful for performing requests to Controllers.
*
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
abstract class AbstractController extends \PHPUnit\Framework\TestCase
abstract class AbstractController extends TestCase
{
protected $_runCode = '';

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

/**
* @var \Magento\Framework\App\RequestInterface
* @var RequestInterface
*/
protected $_request;

/**
* @var \Magento\Framework\App\ResponseInterface
* @var ResponseInterface
*/
protected $_response;

Expand Down Expand Up @@ -103,8 +107,9 @@ protected function assertPostConditions()
*/
public function dispatch($uri)
{
/** @var HttpRequest $request */
$request = $this->getRequest();

$request->setDispatched(false);
$request->setRequestUri($uri);
if ($request->isPost()
&& !array_key_exists('form_key', $request->getPost())
Expand All @@ -119,25 +124,36 @@ public function dispatch($uri)
/**
* Request getter
*
* @return \Magento\Framework\App\RequestInterface|HttpRequest
* @return RequestInterface
*/
public function getRequest()
{
if (!$this->_request) {
$this->_request = $this->_objectManager->get(\Magento\Framework\App\RequestInterface::class);
$this->_request = $this->_objectManager->get(RequestInterface::class);
}
return $this->_request;
}

/**
* Reset Request parameters
*
* @return void
*/
protected function resetRequest(): void
{
$this->_objectManager->removeSharedInstance(RequestInterface::class);
$this->_request = null;
}

/**
* Response getter
*
* @return \Magento\Framework\App\ResponseInterface|HttpResponse
* @return ResponseInterface
*/
public function getResponse()
{
if (!$this->_response) {
$this->_response = $this->_objectManager->get(\Magento\Framework\App\ResponseInterface::class);
$this->_response = $this->_objectManager->get(ResponseInterface::class);
}
return $this->_response;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Controller\Adminhtml;

use Magento\TestFramework\TestCase\AbstractBackendController;

/**
* @magentoAppArea adminhtml
*/
class ConsecutiveCallTest extends AbstractBackendController
{
/**
* Consecutive calls were failing due to `$request['dispatched']` not being reset before request
*/
public function testConsecutiveCallShouldNotFail()
{
$this->dispatch('backend/admin/auth/login');
$this->dispatch('backend/admin/auth/login');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ public function testCreatepasswordActionInvalidToken()
}

/**
* @param int $customerId
* @param int $customerId
* @param string|null $confirmation
*/
private function assertCustomerConfirmationEquals(int $customerId, string $confirmation = null)
{
/** @var \Magento\Customer\Model\Customer $customer */
$customer = Bootstrap::getObjectManager()
->create(\Magento\Customer\Model\Customer::class)->load($customerId);
->create(\Magento\Customer\Model\Customer::class)->load($customerId);
$this->assertEquals($confirmation, $customer->getConfirmation());
}

Expand Down Expand Up @@ -492,14 +492,14 @@ public function testChangePasswordEditPostAction()
->setMethod('POST')
->setPostValue(
[
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
'firstname' => 'John',
'lastname' => 'Doe',
'email' => 'johndoe@email.com',
'change_password' => 1,
'change_email' => 1,
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
'firstname' => 'John',
'lastname' => 'Doe',
'email' => 'johndoe@email.com',
'change_password' => 1,
'change_email' => 1,
'current_password' => 'password',
'password' => 'new-Password1',
'password' => 'new-Password1',
'password_confirmation' => 'new-Password1',
]
);
Expand Down Expand Up @@ -645,6 +645,7 @@ public function testRegisterCustomerWithEmailConfirmation(): void
/** @var CookieManagerInterface $cookieManager */
$cookieManager = $this->_objectManager->get(CookieManagerInterface::class);
$cookieManager->deleteCookie(MessagePlugin::MESSAGES_COOKIES_NAME);

$this->_objectManager->removeSharedInstance(Http::class);
$this->_objectManager->removeSharedInstance(Request::class);
$this->_request = null;
Expand Down Expand Up @@ -761,8 +762,9 @@ public function testResetPasswordWhenEmailChanged(): void
$customer->setEmail($newEmail);
$customerRepository->save($customer);

/* Goes through the link in a mail */
$this->resetRequest();

/* Goes through the link in a mail */
$this->getRequest()
->setParam('token', $token)
->setParam('id', $customerData->getId());
Expand Down Expand Up @@ -842,15 +844,13 @@ private function assertForgotPasswordEmailContent(string $token): void
}

/**
* Clear request object.
*
* @return void
* @inheritDoc
*/
private function resetRequest(): void
protected function resetRequest(): void
{
$this->_objectManager->removeSharedInstance(Http::class);
$this->_objectManager->removeSharedInstance(Request::class);
$this->_request = null;
parent::resetRequest();
}

/**
Expand Down