-
Notifications
You must be signed in to change notification settings - Fork 9.4k
#27500 PHPUnit 8 for module Cookie #27708
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,60 +5,68 @@ | |||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please also declare the
Suggested change
|
||||||||||
namespace Magento\Cookie\Test\Unit\Controller\Index; | ||||||||||
|
||||||||||
use PHPUnit\Framework\TestCase; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same here |
||||||||||
use Magento\Cookie\Controller\Index\NoCookies; | ||||||||||
use PHPUnit\Framework\MockObject\MockObject; | ||||||||||
use Magento\Framework\Event\ManagerInterface; | ||||||||||
use Magento\Framework\App\Request\Http; | ||||||||||
use Magento\Framework\App\Response\RedirectInterface; | ||||||||||
use Magento\Framework\App\ViewInterface; | ||||||||||
use Magento\Framework\DataObject; | ||||||||||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||||||||||
|
||||||||||
class NoCookiesTest extends \PHPUnit\Framework\TestCase | ||||||||||
class NoCookiesTest extends TestCase | ||||||||||
{ | ||||||||||
/** | ||||||||||
* @var \Magento\Cookie\Controller\Index\NoCookies | ||||||||||
* @var NoCookies | ||||||||||
*/ | ||||||||||
private $controller; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\ManagerInterface | ||||||||||
* @var MockObject|ManagerInterface | ||||||||||
*/ | ||||||||||
private $eventManagerMock; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Request\Http | ||||||||||
* @var MockObject|Http | ||||||||||
*/ | ||||||||||
private $requestMock; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Response\Http | ||||||||||
* @var MockObject|\Magento\Framework\App\Response\Http | ||||||||||
*/ | ||||||||||
private $responseMock; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Response\RedirectInterface | ||||||||||
* @var MockObject|RedirectInterface | ||||||||||
*/ | ||||||||||
private $redirectResponseMock; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\ViewInterface | ||||||||||
* @var MockObject|ViewInterface | ||||||||||
*/ | ||||||||||
protected $viewMock; | ||||||||||
|
||||||||||
const REDIRECT_URL = 'http://www.example.com/redirect'; | ||||||||||
const REDIRECT_PATH = '\a\path'; | ||||||||||
const REDIRECT_ARGUMENTS = '&arg1key=arg1value'; | ||||||||||
|
||||||||||
public function setup() | ||||||||||
public function setup(): void | ||||||||||
{ | ||||||||||
$objectManager = new ObjectManager($this); | ||||||||||
$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)->getMock(); | ||||||||||
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) | ||||||||||
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->getMock(); | ||||||||||
$this->requestMock = $this->getMockBuilder(Http::class) | ||||||||||
->disableOriginalConstructor() | ||||||||||
->getMock(); | ||||||||||
$this->responseMock = $this->getMockBuilder(\Magento\Framework\App\Response\Http::class) | ||||||||||
->disableOriginalConstructor() | ||||||||||
->getMock(); | ||||||||||
$this->redirectResponseMock = $this->getMockBuilder(\Magento\Framework\App\Response\RedirectInterface::class) | ||||||||||
$this->redirectResponseMock = $this->getMockBuilder(RedirectInterface::class) | ||||||||||
->getMock(); | ||||||||||
$this->viewMock = $this->createMock(\Magento\Framework\App\ViewInterface::class); | ||||||||||
$this->viewMock = $this->createMock(ViewInterface::class); | ||||||||||
|
||||||||||
$this->controller = $objectManager->getObject( | ||||||||||
\Magento\Cookie\Controller\Index\NoCookies::class, | ||||||||||
NoCookies::class, | ||||||||||
[ | ||||||||||
'eventManager' => $this->eventManagerMock, | ||||||||||
'request' => $this->requestMock, | ||||||||||
|
@@ -79,7 +87,7 @@ public function testExecuteRedirectUrl() | |||||||||
$this->callback( | ||||||||||
function ($dataArray) { | ||||||||||
$redirect = $dataArray['redirect']; | ||||||||||
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $redirect); | ||||||||||
$this->assertInstanceOf(DataObject::class, $redirect); | ||||||||||
$redirect->setRedirectUrl(self::REDIRECT_URL); | ||||||||||
return true; | ||||||||||
} | ||||||||||
|
@@ -108,7 +116,7 @@ public function testExecuteRedirectPath() | |||||||||
$this->callback( | ||||||||||
function ($dataArray) { | ||||||||||
$redirect = $dataArray['redirect']; | ||||||||||
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $redirect); | ||||||||||
$this->assertInstanceOf(DataObject::class, $redirect); | ||||||||||
$redirect->setArguments(self::REDIRECT_ARGUMENTS); | ||||||||||
$redirect->setPath(self::REDIRECT_PATH); | ||||||||||
$redirect->setRedirect(self::REDIRECT_URL); | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,39 +5,49 @@ | |||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
namespace Magento\Cookie\Test\Unit\Helper; | ||||||||||
|
||||||||||
class CookieTest extends \PHPUnit\Framework\TestCase | ||||||||||
use PHPUnit\Framework\TestCase; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||||||||
use Magento\Cookie\Helper\Cookie; | ||||||||||
use Magento\Framework\App\Request\Http; | ||||||||||
use Magento\Framework\App\Helper\Context; | ||||||||||
use Magento\Store\Model\StoreManager; | ||||||||||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||||||||||
use Magento\Store\Model\Store; | ||||||||||
use PHPUnit\Framework\MockObject\MockObject; | ||||||||||
use Magento\Store\Model\Website; | ||||||||||
|
||||||||||
class CookieTest extends TestCase | ||||||||||
{ | ||||||||||
/** | ||||||||||
* @var \Magento\Cookie\Helper\Cookie | ||||||||||
* @var Cookie | ||||||||||
*/ | ||||||||||
protected $_object; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \Magento\Framework\App\Request\Http | ||||||||||
* @var Http | ||||||||||
*/ | ||||||||||
protected $_request; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var \Magento\Framework\App\Helper\Context | ||||||||||
* @var Context | ||||||||||
*/ | ||||||||||
protected $_context; | ||||||||||
|
||||||||||
public function testIsUserNotAllowSaveCookie() | ||||||||||
{ | ||||||||||
$this->_initMock()->_getCookieStub([1 => 1]); | ||||||||||
$this->assertFalse($this->_object->isUserNotAllowSaveCookie()); | ||||||||||
$request = $this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getCookie']); | ||||||||||
$request = $this->createPartialMock(Http::class, ['getCookie']); | ||||||||||
$request->expects($this->any())->method('getCookie')->will($this->returnValue(json_encode([]))); | ||||||||||
$scopeConfig = $this->_getConfigStub(); | ||||||||||
$context = $this->createPartialMock( | ||||||||||
\Magento\Framework\App\Helper\Context::class, | ||||||||||
Context::class, | ||||||||||
['getRequest', 'getScopeConfig'] | ||||||||||
); | ||||||||||
$context->expects($this->once())->method('getRequest')->will($this->returnValue($request)); | ||||||||||
$context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); | ||||||||||
$this->_object = new \Magento\Cookie\Helper\Cookie( | ||||||||||
$this->_object = new Cookie( | ||||||||||
$context, | ||||||||||
$this->createMock(\Magento\Store\Model\StoreManager::class), | ||||||||||
$this->createMock(StoreManager::class), | ||||||||||
['current_store' => $this->_getStoreStub(), 'website' => $this->_getWebsiteStub()] | ||||||||||
); | ||||||||||
$this->assertTrue($this->_object->isUserNotAllowSaveCookie()); | ||||||||||
|
@@ -52,8 +62,8 @@ public function testGetAcceptedSaveCookiesWebsiteIds() | |||||||||
public function testGetCookieRestrictionLifetime() | ||||||||||
{ | ||||||||||
$this->_request = | ||||||||||
$this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getCookie']); | ||||||||||
$scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); | ||||||||||
$this->createPartialMock(Http::class, ['getCookie']); | ||||||||||
$scopeConfig = $this->createMock(ScopeConfigInterface::class); | ||||||||||
$storeStub = $this->_getStoreStub(); | ||||||||||
$scopeConfig->expects( | ||||||||||
$this->once() | ||||||||||
|
@@ -65,15 +75,15 @@ public function testGetCookieRestrictionLifetime() | |||||||||
$this->equalTo('web/cookie/cookie_restriction_lifetime') | ||||||||||
); | ||||||||||
$this->_context = $this->createPartialMock( | ||||||||||
\Magento\Framework\App\Helper\Context::class, | ||||||||||
Context::class, | ||||||||||
['getRequest', 'getScopeConfig'] | ||||||||||
); | ||||||||||
$this->_context->expects($this->once())->method('getRequest')->will($this->returnValue($this->_request)); | ||||||||||
$this->_context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); | ||||||||||
|
||||||||||
$this->_object = new \Magento\Cookie\Helper\Cookie( | ||||||||||
$this->_object = new Cookie( | ||||||||||
$this->_context, | ||||||||||
$this->createMock(\Magento\Store\Model\StoreManager::class), | ||||||||||
$this->createMock(StoreManager::class), | ||||||||||
['current_store' => $storeStub, 'website' => $this->_getWebsiteStub()] | ||||||||||
); | ||||||||||
$this->assertEquals($this->_object->getCookieRestrictionLifetime(), 60 * 60 * 24 * 365); | ||||||||||
|
@@ -86,39 +96,39 @@ protected function _initMock() | |||||||||
{ | ||||||||||
$scopeConfig = $this->_getConfigStub(); | ||||||||||
$this->_request = | ||||||||||
$this->createPartialMock(\Magento\Framework\App\Request\Http::class, ['getCookie']); | ||||||||||
$this->createPartialMock(Http::class, ['getCookie']); | ||||||||||
$this->_context = $this->createPartialMock( | ||||||||||
\Magento\Framework\App\Helper\Context::class, | ||||||||||
Context::class, | ||||||||||
['getRequest', 'getScopeConfig'] | ||||||||||
); | ||||||||||
$this->_context->expects($this->once())->method('getRequest')->will($this->returnValue($this->_request)); | ||||||||||
$this->_context->expects($this->once())->method('getScopeConfig')->will($this->returnValue($scopeConfig)); | ||||||||||
$this->_object = new \Magento\Cookie\Helper\Cookie( | ||||||||||
$this->_object = new Cookie( | ||||||||||
$this->_context, | ||||||||||
$this->createMock(\Magento\Store\Model\StoreManager::class), | ||||||||||
$this->createMock(StoreManager::class), | ||||||||||
['current_store' => $this->_getStoreStub(), 'website' => $this->_getWebsiteStub()] | ||||||||||
); | ||||||||||
return $this; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Create store stub | ||||||||||
* @return \Magento\Store\Model\Store | ||||||||||
* @return Store | ||||||||||
*/ | ||||||||||
protected function _getStoreStub() | ||||||||||
{ | ||||||||||
$store = $this->createMock(\Magento\Store\Model\Store::class); | ||||||||||
$store = $this->createMock(Store::class); | ||||||||||
return $store; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Create config stub | ||||||||||
* | ||||||||||
* @return \PHPUnit_Framework_MockObject_MockObject | ||||||||||
* @return MockObject | ||||||||||
*/ | ||||||||||
protected function _getConfigStub() | ||||||||||
{ | ||||||||||
$scopeConfig = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); | ||||||||||
$scopeConfig = $this->createMock(ScopeConfigInterface::class); | ||||||||||
$scopeConfig->expects( | ||||||||||
$this->any() | ||||||||||
)->method( | ||||||||||
|
@@ -152,7 +162,7 @@ protected function _getCookieStub($cookieString = []) | |||||||||
*/ | ||||||||||
protected function _getWebsiteStub() | ||||||||||
{ | ||||||||||
$websiteMock = $this->createMock(\Magento\Store\Model\Website::class); | ||||||||||
$websiteMock = $this->createMock(Website::class); | ||||||||||
|
||||||||||
$websiteMock->expects($this->any())->method('getId')->will($this->returnValue(1)); | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,29 +5,36 @@ | |||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
namespace Magento\Cookie\Test\Unit\Model\Config\Backend; | ||||||||||
|
||||||||||
use PHPUnit\Framework\TestCase; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||||||||
use Magento\Framework\Model\ResourceModel\AbstractResource; | ||||||||||
use PHPUnit\Framework\MockObject\MockObject; | ||||||||||
use Magento\Cookie\Model\Config\Backend\Domain; | ||||||||||
use Magento\Framework\Event\Manager; | ||||||||||
use Magento\Framework\Model\Context; | ||||||||||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||||||||||
use Magento\Framework\Exception\LocalizedException; | ||||||||||
use Magento\Framework\Session\Config\Validator\CookieDomainValidator; | ||||||||||
|
||||||||||
/** | ||||||||||
* Test \Magento\Cookie\Model\Config\Backend\Domain | ||||||||||
*/ | ||||||||||
class DomainTest extends \PHPUnit\Framework\TestCase | ||||||||||
class DomainTest extends TestCase | ||||||||||
{ | ||||||||||
/** @var \Magento\Framework\Model\ResourceModel\AbstractResource | \PHPUnit_Framework_MockObject_MockObject */ | ||||||||||
/** @var AbstractResource|MockObject */ | ||||||||||
protected $resourceMock; | ||||||||||
|
||||||||||
/** @var \Magento\Cookie\Model\Config\Backend\Domain */ | ||||||||||
/** @var Domain */ | ||||||||||
protected $domain; | ||||||||||
|
||||||||||
/** | ||||||||||
* @var CookieDomainValidator | \PHPUnit_Framework_MockObject_MockObject | ||||||||||
* @var CookieDomainValidator|MockObject | ||||||||||
*/ | ||||||||||
protected $validatorMock; | ||||||||||
|
||||||||||
protected function setUp() | ||||||||||
protected function setUp(): void | ||||||||||
{ | ||||||||||
$eventDispatcherMock = $this->createMock(\Magento\Framework\Event\Manager::class); | ||||||||||
$contextMock = $this->createMock(\Magento\Framework\Model\Context::class); | ||||||||||
$eventDispatcherMock = $this->createMock(Manager::class); | ||||||||||
$contextMock = $this->createMock(Context::class); | ||||||||||
$contextMock->expects( | ||||||||||
$this->any() | ||||||||||
)->method( | ||||||||||
|
@@ -36,7 +43,7 @@ protected function setUp() | |||||||||
$this->returnValue($eventDispatcherMock) | ||||||||||
); | ||||||||||
|
||||||||||
$this->resourceMock = $this->createPartialMock(\Magento\Framework\Model\ResourceModel\AbstractResource::class, [ | ||||||||||
$this->resourceMock = $this->createPartialMock(AbstractResource::class, [ | ||||||||||
'_construct', | ||||||||||
'getConnection', | ||||||||||
'getIdFieldName', | ||||||||||
|
@@ -48,12 +55,12 @@ protected function setUp() | |||||||||
]); | ||||||||||
|
||||||||||
$this->validatorMock = $this->getMockBuilder( | ||||||||||
\Magento\Framework\Session\Config\Validator\CookieDomainValidator::class | ||||||||||
CookieDomainValidator::class | ||||||||||
)->disableOriginalConstructor() | ||||||||||
->getMock(); | ||||||||||
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||||||||||
$helper = new ObjectManager($this); | ||||||||||
$this->domain = $helper->getObject( | ||||||||||
\Magento\Cookie\Model\Config\Backend\Domain::class, | ||||||||||
Domain::class, | ||||||||||
[ | ||||||||||
'context' => $contextMock, | ||||||||||
'resource' => $this->resourceMock, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please sort these imports ascending?